Skip to content

Commit

Permalink
Repair converting -0 to +0 in native collections
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Dec 11, 2014
1 parent 116a57b commit 280fcfe
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 90 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ var core = require('core-js/library');
require('core-js/shim');
```
## Changelog
**0.2.1** - *2014.12.12* - **Repair converting -0 to +0 in [native collections](#ecmascript-6-collections)**
**0.2.0** - *2014.12.06*
* added [`es7`](#ecmascript-7), [`es7_refs`](#ecmascript-7-abstract-references) modules
* added [`String#at`](#ecmascript-7)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "core.js",
"main": "client/core.js",
"version": "0.2.0",
"version": "0.2.1",
"description": "Standard Library",
"keywords": [
"ES6",
Expand Down
2 changes: 1 addition & 1 deletion build/config.ls
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
config = module.exports = {}
..version = '0.2.0'
..version = '0.2.1'
..year = new Date!getFullYear!
..banner = """
/**
Expand Down
24 changes: 14 additions & 10 deletions client/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Core.js 0.2.0
* Core.js 0.2.1
* https://github.com/zloirock/core-js
* License: http://rock.mit-license.org
* © 2014 Denis Pushkarev
Expand Down Expand Up @@ -1296,9 +1296,9 @@ $define(GLOBAL + BIND, {
}});
} else {
var Native = C
, test_key = {}
, collection = new C
, adder = collection[ADDER_KEY];
, adder = collection[ADDER_KEY]
, buggyChaining, buggyZero;
// wrap to init collections from iterable
if(!(SYMBOL_ITERATOR in ArrayProto && C.length)){
C = function(iterable){
Expand All @@ -1307,10 +1307,14 @@ $define(GLOBAL + BIND, {
}
C[PROTOTYPE] = Native[PROTOTYPE];
}
// fix .add & .set for chaining
if(framework && collection[ADDER_KEY](test_key, 1) !== collection){
buggyChaining = collection[ADDER_KEY](isWeak ? {} : -0, 1) !== collection;
isWeak || collection.forEach(function(val, key){
if(same(key, -0))buggyZero = true;
});
// fix .add & .set for chaining & converting -0 key to +0
if(framework && (buggyChaining || buggyZero)){
hidden(C[PROTOTYPE], ADDER_KEY, function(a, b){
adder.call(this, a, b);
adder.call(this, same(a, -0) ? 0 : a, b);
return this;
});
}
Expand Down Expand Up @@ -1493,14 +1497,14 @@ $define(GLOBAL + BIND, {
referenceDelete: REFERENCE_DELETE
});

FunctionProto[REFERENCE_GET] || hidden(FunctionProto, REFERENCE_GET, returnThis);
hidden(FunctionProto, REFERENCE_GET, returnThis);

function setMapMethods(Constructor){
if(Constructor){
var MapProto = Constructor[PROTOTYPE];
MapProto[REFERENCE_GET] || hidden(MapProto, REFERENCE_GET, MapProto.get);
MapProto[REFERENCE_SET] || hidden(MapProto, REFERENCE_SET, MapProto.set);
MapProto[REFERENCE_DELETE] || hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
hidden(MapProto, REFERENCE_GET, MapProto.get);
hidden(MapProto, REFERENCE_SET, MapProto.set);
hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
}
}
setMapMethods(Map);
Expand Down
4 changes: 2 additions & 2 deletions client/core.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/core.min.map

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions client/library.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Core.js 0.2.0
* Core.js 0.2.1
* https://github.com/zloirock/core-js
* License: http://rock.mit-license.org
* © 2014 Denis Pushkarev
Expand Down Expand Up @@ -1296,9 +1296,9 @@ $define(GLOBAL + BIND, {
}});
} else {
var Native = C
, test_key = {}
, collection = new C
, adder = collection[ADDER_KEY];
, adder = collection[ADDER_KEY]
, buggyChaining, buggyZero;
// wrap to init collections from iterable
if(!(SYMBOL_ITERATOR in ArrayProto && C.length)){
C = function(iterable){
Expand All @@ -1307,10 +1307,14 @@ $define(GLOBAL + BIND, {
}
C[PROTOTYPE] = Native[PROTOTYPE];
}
// fix .add & .set for chaining
if(framework && collection[ADDER_KEY](test_key, 1) !== collection){
buggyChaining = collection[ADDER_KEY](isWeak ? {} : -0, 1) !== collection;
isWeak || collection.forEach(function(val, key){
if(same(key, -0))buggyZero = true;
});
// fix .add & .set for chaining & converting -0 key to +0
if(framework && (buggyChaining || buggyZero)){
hidden(C[PROTOTYPE], ADDER_KEY, function(a, b){
adder.call(this, a, b);
adder.call(this, same(a, -0) ? 0 : a, b);
return this;
});
}
Expand Down Expand Up @@ -1493,14 +1497,14 @@ $define(GLOBAL + BIND, {
referenceDelete: REFERENCE_DELETE
});

FunctionProto[REFERENCE_GET] || hidden(FunctionProto, REFERENCE_GET, returnThis);
hidden(FunctionProto, REFERENCE_GET, returnThis);

function setMapMethods(Constructor){
if(Constructor){
var MapProto = Constructor[PROTOTYPE];
MapProto[REFERENCE_GET] || hidden(MapProto, REFERENCE_GET, MapProto.get);
MapProto[REFERENCE_SET] || hidden(MapProto, REFERENCE_SET, MapProto.set);
MapProto[REFERENCE_DELETE] || hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
hidden(MapProto, REFERENCE_GET, MapProto.get);
hidden(MapProto, REFERENCE_SET, MapProto.set);
hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
}
}
setMapMethods(Map);
Expand Down
4 changes: 2 additions & 2 deletions client/library.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/library.min.map

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions client/shim.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Core.js 0.2.0
* Core.js 0.2.1
* https://github.com/zloirock/core-js
* License: http://rock.mit-license.org
* © 2014 Denis Pushkarev
Expand Down Expand Up @@ -1296,9 +1296,9 @@ $define(GLOBAL + BIND, {
}});
} else {
var Native = C
, test_key = {}
, collection = new C
, adder = collection[ADDER_KEY];
, adder = collection[ADDER_KEY]
, buggyChaining, buggyZero;
// wrap to init collections from iterable
if(!(SYMBOL_ITERATOR in ArrayProto && C.length)){
C = function(iterable){
Expand All @@ -1307,10 +1307,14 @@ $define(GLOBAL + BIND, {
}
C[PROTOTYPE] = Native[PROTOTYPE];
}
// fix .add & .set for chaining
if(framework && collection[ADDER_KEY](test_key, 1) !== collection){
buggyChaining = collection[ADDER_KEY](isWeak ? {} : -0, 1) !== collection;
isWeak || collection.forEach(function(val, key){
if(same(key, -0))buggyZero = true;
});
// fix .add & .set for chaining & converting -0 key to +0
if(framework && (buggyChaining || buggyZero)){
hidden(C[PROTOTYPE], ADDER_KEY, function(a, b){
adder.call(this, a, b);
adder.call(this, same(a, -0) ? 0 : a, b);
return this;
});
}
Expand Down Expand Up @@ -1493,14 +1497,14 @@ $define(GLOBAL + BIND, {
referenceDelete: REFERENCE_DELETE
});

FunctionProto[REFERENCE_GET] || hidden(FunctionProto, REFERENCE_GET, returnThis);
hidden(FunctionProto, REFERENCE_GET, returnThis);

function setMapMethods(Constructor){
if(Constructor){
var MapProto = Constructor[PROTOTYPE];
MapProto[REFERENCE_GET] || hidden(MapProto, REFERENCE_GET, MapProto.get);
MapProto[REFERENCE_SET] || hidden(MapProto, REFERENCE_SET, MapProto.set);
MapProto[REFERENCE_DELETE] || hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
hidden(MapProto, REFERENCE_GET, MapProto.get);
hidden(MapProto, REFERENCE_SET, MapProto.set);
hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
}
}
setMapMethods(Map);
Expand Down
4 changes: 2 additions & 2 deletions client/shim.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/shim.min.map

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Core.js 0.2.0
* Core.js 0.2.1
* https://github.com/zloirock/core-js
* License: http://rock.mit-license.org
* © 2014 Denis Pushkarev
Expand Down Expand Up @@ -1089,9 +1089,9 @@ $define(GLOBAL + BIND, {
}});
} else {
var Native = C
, test_key = {}
, collection = new C
, adder = collection[ADDER_KEY];
, adder = collection[ADDER_KEY]
, buggyChaining, buggyZero;
// wrap to init collections from iterable
if(!(SYMBOL_ITERATOR in ArrayProto && C.length)){
C = function(iterable){
Expand All @@ -1100,10 +1100,14 @@ $define(GLOBAL + BIND, {
}
C[PROTOTYPE] = Native[PROTOTYPE];
}
// fix .add & .set for chaining
if(framework && collection[ADDER_KEY](test_key, 1) !== collection){
buggyChaining = collection[ADDER_KEY](isWeak ? {} : -0, 1) !== collection;
isWeak || collection.forEach(function(val, key){
if(same(key, -0))buggyZero = true;
});
// fix .add & .set for chaining & converting -0 key to +0
if(framework && (buggyChaining || buggyZero)){
hidden(C[PROTOTYPE], ADDER_KEY, function(a, b){
adder.call(this, a, b);
adder.call(this, same(a, -0) ? 0 : a, b);
return this;
});
}
Expand Down Expand Up @@ -1286,14 +1290,14 @@ $define(GLOBAL + BIND, {
referenceDelete: REFERENCE_DELETE
});

FunctionProto[REFERENCE_GET] || hidden(FunctionProto, REFERENCE_GET, returnThis);
hidden(FunctionProto, REFERENCE_GET, returnThis);

function setMapMethods(Constructor){
if(Constructor){
var MapProto = Constructor[PROTOTYPE];
MapProto[REFERENCE_GET] || hidden(MapProto, REFERENCE_GET, MapProto.get);
MapProto[REFERENCE_SET] || hidden(MapProto, REFERENCE_SET, MapProto.set);
MapProto[REFERENCE_DELETE] || hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
hidden(MapProto, REFERENCE_GET, MapProto.get);
hidden(MapProto, REFERENCE_SET, MapProto.set);
hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
}
}
setMapMethods(Map);
Expand Down
24 changes: 14 additions & 10 deletions library.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Core.js 0.2.0
* Core.js 0.2.1
* https://github.com/zloirock/core-js
* License: http://rock.mit-license.org
* © 2014 Denis Pushkarev
Expand Down Expand Up @@ -1089,9 +1089,9 @@ $define(GLOBAL + BIND, {
}});
} else {
var Native = C
, test_key = {}
, collection = new C
, adder = collection[ADDER_KEY];
, adder = collection[ADDER_KEY]
, buggyChaining, buggyZero;
// wrap to init collections from iterable
if(!(SYMBOL_ITERATOR in ArrayProto && C.length)){
C = function(iterable){
Expand All @@ -1100,10 +1100,14 @@ $define(GLOBAL + BIND, {
}
C[PROTOTYPE] = Native[PROTOTYPE];
}
// fix .add & .set for chaining
if(framework && collection[ADDER_KEY](test_key, 1) !== collection){
buggyChaining = collection[ADDER_KEY](isWeak ? {} : -0, 1) !== collection;
isWeak || collection.forEach(function(val, key){
if(same(key, -0))buggyZero = true;
});
// fix .add & .set for chaining & converting -0 key to +0
if(framework && (buggyChaining || buggyZero)){
hidden(C[PROTOTYPE], ADDER_KEY, function(a, b){
adder.call(this, a, b);
adder.call(this, same(a, -0) ? 0 : a, b);
return this;
});
}
Expand Down Expand Up @@ -1286,14 +1290,14 @@ $define(GLOBAL + BIND, {
referenceDelete: REFERENCE_DELETE
});

FunctionProto[REFERENCE_GET] || hidden(FunctionProto, REFERENCE_GET, returnThis);
hidden(FunctionProto, REFERENCE_GET, returnThis);

function setMapMethods(Constructor){
if(Constructor){
var MapProto = Constructor[PROTOTYPE];
MapProto[REFERENCE_GET] || hidden(MapProto, REFERENCE_GET, MapProto.get);
MapProto[REFERENCE_SET] || hidden(MapProto, REFERENCE_SET, MapProto.set);
MapProto[REFERENCE_DELETE] || hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
hidden(MapProto, REFERENCE_GET, MapProto.get);
hidden(MapProto, REFERENCE_SET, MapProto.set);
hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
}
}
setMapMethods(Map);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "core-js",
"description": "Standard library",
"version": "0.2.0",
"version": "0.2.1",
"repository": {
"type": "git",
"url": "https://github.com/zloirock/core-js.git"
Expand Down
24 changes: 14 additions & 10 deletions shim.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Core.js 0.2.0
* Core.js 0.2.1
* https://github.com/zloirock/core-js
* License: http://rock.mit-license.org
* © 2014 Denis Pushkarev
Expand Down Expand Up @@ -1089,9 +1089,9 @@ $define(GLOBAL + BIND, {
}});
} else {
var Native = C
, test_key = {}
, collection = new C
, adder = collection[ADDER_KEY];
, adder = collection[ADDER_KEY]
, buggyChaining, buggyZero;
// wrap to init collections from iterable
if(!(SYMBOL_ITERATOR in ArrayProto && C.length)){
C = function(iterable){
Expand All @@ -1100,10 +1100,14 @@ $define(GLOBAL + BIND, {
}
C[PROTOTYPE] = Native[PROTOTYPE];
}
// fix .add & .set for chaining
if(framework && collection[ADDER_KEY](test_key, 1) !== collection){
buggyChaining = collection[ADDER_KEY](isWeak ? {} : -0, 1) !== collection;
isWeak || collection.forEach(function(val, key){
if(same(key, -0))buggyZero = true;
});
// fix .add & .set for chaining & converting -0 key to +0
if(framework && (buggyChaining || buggyZero)){
hidden(C[PROTOTYPE], ADDER_KEY, function(a, b){
adder.call(this, a, b);
adder.call(this, same(a, -0) ? 0 : a, b);
return this;
});
}
Expand Down Expand Up @@ -1286,14 +1290,14 @@ $define(GLOBAL + BIND, {
referenceDelete: REFERENCE_DELETE
});

FunctionProto[REFERENCE_GET] || hidden(FunctionProto, REFERENCE_GET, returnThis);
hidden(FunctionProto, REFERENCE_GET, returnThis);

function setMapMethods(Constructor){
if(Constructor){
var MapProto = Constructor[PROTOTYPE];
MapProto[REFERENCE_GET] || hidden(MapProto, REFERENCE_GET, MapProto.get);
MapProto[REFERENCE_SET] || hidden(MapProto, REFERENCE_SET, MapProto.set);
MapProto[REFERENCE_DELETE] || hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
hidden(MapProto, REFERENCE_GET, MapProto.get);
hidden(MapProto, REFERENCE_SET, MapProto.set);
hidden(MapProto, REFERENCE_DELETE, MapProto['delete']);
}
}
setMapMethods(Map);
Expand Down
14 changes: 9 additions & 5 deletions src/es6_collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
}});
} else {
var Native = C
, test_key = {}
, collection = new C
, adder = collection[ADDER_KEY];
, adder = collection[ADDER_KEY]
, buggyChaining, buggyZero;
// wrap to init collections from iterable
if(!(SYMBOL_ITERATOR in ArrayProto && C.length)){
C = function(iterable){
Expand All @@ -42,10 +42,14 @@
}
C[PROTOTYPE] = Native[PROTOTYPE];
}
// fix .add & .set for chaining
if(framework && collection[ADDER_KEY](test_key, 1) !== collection){
buggyChaining = collection[ADDER_KEY](isWeak ? {} : -0, 1) !== collection;
isWeak || collection.forEach(function(val, key){
if(same(key, -0))buggyZero = true;
});
// fix .add & .set for chaining & converting -0 key to +0
if(framework && (buggyChaining || buggyZero)){
hidden(C[PROTOTYPE], ADDER_KEY, function(a, b){
adder.call(this, a, b);
adder.call(this, same(a, -0) ? 0 : a, b);
return this;
});
}
Expand Down
Loading

0 comments on commit 280fcfe

Please sign in to comment.