You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### <aid="__proto__"></a> Warning About `__proto__`
82
+
Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto). Assigning to the `__proto__` property, even if done dynamically via `obj[key] = {foo: 42}` changes the object's _prototype_, rather than merely giving it a new property named `__proto__`. That also means if you've got an object with a plain `__proto__` property (like when parsing JSON) and pass it to Oolong's `assign`, it could inadvertently overwrite the target's prototype:
In other situations, like when you're merging two objects recursively with `merge`, this could cause the global prototype (`Object.prototype`) to be modified.
101
+
102
+
As Oolong.js is written primarily for ECMAScript 5 compliant runtimes with no engine-specific workarounds, it doesn't have special handling for ignoring `__proto__`. Unfortunately, even if it did, the presence of such special properties is far too likely to cause issues elsewhere to make a difference. It's quite common to assign dynamic values to object keys, e.g. when indexing an array (by creating an object with keys as values). Fortunately, you can and should **disable `__proto__` globally** by overwriting it on the global `Object.prototype`:
After overwriting `__proto__` on `Object.prototype`, assigning, merging or cloning objects with `__proto__` properties won't behave in any special manner. Assignments to `__proto__` will become regular property assignments:
Copy file name to clipboardExpand all lines: doc/API.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,8 @@ Returns `target`.
52
52
53
53
Think of it as _extending_ the first object step by step with others.
54
54
55
+
**Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
Think of it as _extending_ the first object step by step with others.
67
69
70
+
**Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
@@ -76,6 +80,8 @@ Creates a shallow clone of the given object, taking all enumerable
76
80
properties into account.
77
81
Shallow means if you've got nested objects, those will be shared.
78
82
83
+
**Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
Creates a deep clone of the given object, taking all enumerable properties
87
93
into account.
88
94
95
+
**Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
@@ -99,6 +107,8 @@ Uses `Object.create` and [`Oolong.assign`](#Oolong.assign)
99
107
internally.
100
108
Does not modify the given `prototype` nor source objects.
101
109
110
+
**Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
111
+
102
112
**Examples**:
103
113
```javascript
104
114
varPERSON= {name:"Unknown", age:0}
@@ -118,6 +128,8 @@ will be skipped. Usually that's not a problem, but if you want to use
118
128
`Oolong.defaults` for hashmaps/dictionaries with unknown keys, ensure
119
129
`target` inherits from `null` instead (use `Object.create(null)`).
120
130
131
+
**Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
132
+
121
133
**Examples**:
122
134
```javascript
123
135
varPERSON= {name:"Unknown", age:0, shirt:"blue"}
@@ -380,6 +392,8 @@ a plain object. Does not modify anything in the source objects.
380
392
381
393
Think of it as _extending_ the first object step by step with others.
382
394
395
+
**Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
396
+
383
397
**Examples**:
384
398
```javascript
385
399
var person = {name:"John", attributes: {age:42}}
@@ -487,7 +501,7 @@ Set the prototype of the given object to the given prototype.
487
501
Pass `null` or another object for the prototype.
488
502
Returns `object`.
489
503
490
-
Uses `Object.setPrototypeOf` if it exists. Otherwise uses a polyfill.
504
+
Uses `Object.setPrototypeOf` if it exists. Otherwise uses a polyfill that depends on the presence of the non-standard [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) property.
Copy file name to clipboardExpand all lines: index.js
+15-1Lines changed: 15 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,8 @@ var SET_PROTO_OF_NULL = "Oolong.setPrototypeOf called on null or undefined"
18
18
*
19
19
* Think of it as _extending_ the first object step by step with others.
20
20
*
21
+
* **Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
@@ -43,6 +45,8 @@ exports.assign = function assign(target) {
43
45
*
44
46
* Think of it as _extending_ the first object step by step with others.
45
47
*
48
+
* **Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
@@ -66,6 +70,8 @@ exports.assignOwn = function assignOwn(target) {
66
70
* properties into account.
67
71
* Shallow means if you've got nested objects, those will be shared.
68
72
*
73
+
* **Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
74
+
*
69
75
* @example
70
76
* Oolong.clone({name: "John", age: 32})
71
77
* // => {name: "John", age: 32}
@@ -82,6 +88,8 @@ exports.clone = function clone(obj) {
82
88
* Creates a deep clone of the given object, taking all enumerable properties
83
89
* into account.
84
90
*
91
+
* **Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
@@ -101,6 +109,8 @@ exports.cloneDeep = function cloneDeep(obj) {
101
109
* internally.
102
110
* Does not modify the given `prototype` nor source objects.
103
111
*
112
+
* **Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
@@ -128,6 +138,8 @@ exports.create = function create(obj) {
128
138
* `Oolong.defaults` for hashmaps/dictionaries with unknown keys, ensure
129
139
* `target` inherits from `null` instead (use `Object.create(null)`).
130
140
*
141
+
* **Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
142
+
*
131
143
* @example
132
144
* var PERSON = {name: "Unknown", age: 0, shirt: "blue"}
* Think of it as _extending_ the first object step by step with others.
575
587
*
588
+
* **Warning**: Some JavaScript runtimes, notably V8 (used by Chrome and Node.js) support a nonstandard (as of ECMAScript 5) property called [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) that could cause unwanted behavior. Please see the [README](https://github.com/moll/js-oolong/blob/master/README.md#__proto__) for more details.
589
+
*
576
590
* @example
577
591
* var person = {name: "John", attributes: {age: 42}}
* Pass `null` or another object for the prototype.
778
792
* Returns `object`.
779
793
*
780
-
* Uses `Object.setPrototypeOf` if it exists. Otherwise uses a polyfill.
794
+
* Uses `Object.setPrototypeOf` if it exists. Otherwise uses a polyfill that depends on the presence of the non-standard [`__proto__`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto) property.
0 commit comments