-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Object.prototype should be an immutable prototype exotic object.
This means that any attempts to set the [[Prototype]] slot of the Object Prototype Object (the object which is initially pointed to by Object.prototype) notably by using Object.prototype.__proto__ or Object.setPrototypeOf(Object.prototype, otherObject) should fail with a TypeError as per spec. This is the only exotic behavior of this object. I chose to implement this by adding the virtual method IsProtoImmutable to RecyclableObject with the default return value false, and to override this function in ObjectPrototypeObject to return true. This allows for a future implementation of Object.setImmutablePrototype which would allow other objects to exhibit this behavior. A flag could be added which can be set, and this method would return the value of that flag. In that case, the implementation in ObjectPrototypeObject should remain hardcoded to false to avoid accidentally allowing the value if IsProtoImmutable to change. Removed defunct test. See 19.1.3: The Object prototype object is the intrinsic object %ObjectPrototype%. The Object prototype object is an immutable prototype exotic object. See 9.4.7: An immutable prototype exotic object is an exotic object that has an immutable [[Prototype]] internal slot. Fixes #261 Removed redundant and defunct tests, fixed error description.
- Loading branch information
Showing
9 changed files
with
75 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//------------------------------------------------------------------------------------------------------- | ||
// Copyright (C) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. | ||
//------------------------------------------------------------------------------------------------------- | ||
|
||
// ES7 Object Prototype object has an immutable [[Prototype]] internal slot | ||
// See: 19.1.3 Properties of the Object Prototype Object | ||
// See: 9.4.7 Immutable Prototype Exotic Objects | ||
|
||
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js"); | ||
|
||
var tests = [ | ||
{ | ||
name: "Not okay to set Object.prototype.[[Prototype]] using __proto__", | ||
body: function () { | ||
var objectPrototypeObject = Object.getPrototypeOf(Object.prototype) | ||
var b = Object.create(null) | ||
|
||
assert.throws(function () { Object.prototype.__proto__ = b }, | ||
TypeError, | ||
"It should not be okay to set Object.prototype.[[Prototype]] using __proto__", | ||
"Can't set the prototype of this object.") | ||
|
||
assert.areEqual(objectPrototypeObject, Object.prototype.__proto__, "Object.prototype.__proto__ is unchanged") | ||
assert.areEqual(objectPrototypeObject, Object.getPrototypeOf(Object.prototype), "Object.getPrototypeOf(Object.prototype) is unchanged") | ||
} | ||
}, | ||
{ | ||
name: "Not okay to set Object.prototype.[[Prototype]] using Object.setPrototypeOf", | ||
body: function () { | ||
var objectPrototypeObject = Object.getPrototypeOf(Object.prototype) | ||
var b = Object.create(null) | ||
|
||
assert.throws(function () { Object.setPrototypeOf(Object.prototype, b) }, | ||
TypeError, | ||
"It should not be okay to set Object.prototype.[[Prototype]] using Object.setPrototypeOf", | ||
"Can't set the prototype of this object.") | ||
|
||
assert.areEqual(objectPrototypeObject, Object.prototype.__proto__, "Object.prototype.__proto__ is unchanged") | ||
assert.areEqual(objectPrototypeObject, Object.getPrototypeOf(Object.prototype), "Object.getPrototypeOf(Object.prototype) is unchanged") | ||
} | ||
}, | ||
]; | ||
|
||
testRunner.runTests(tests, { verbose: WScript.Arguments[0] != "summary" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters