From d2a8454d2f599cb18accd4be068d322665c93179 Mon Sep 17 00:00:00 2001 From: whessev8 Date: Fri, 3 Oct 2008 12:14:29 +0000 Subject: [PATCH] This change removes the %AddProperty native JavaScript function from V8. All uses of %AddProperty are replaced by %SetProperty. A few uses of IgnoreAttributesAndSetLocalProperty are added, and the runtime version of it adds a PropertyAttributes argument. Only the JSObject class in objects.cc now uses AddProperty, and it can become private. Review URL: http://codereview.chromium.org/6445 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@426 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/apinatives.js | 2 +- src/array.js | 4 +- src/date-delay.js | 2 +- src/math.js | 42 ++++++++++--- src/messages.js | 6 +- src/regexp-delay.js | 2 +- src/runtime.cc | 50 +++++++-------- src/runtime.h | 3 +- src/string.js | 2 +- src/v8natives.js | 105 +++++++++++++++++++------------- test/mjsunit/regress/regress-1199637.js | 16 ++--- 11 files changed, 140 insertions(+), 94 deletions(-) diff --git a/src/apinatives.js b/src/apinatives.js index 6a3d9e4..8741f59 100644 --- a/src/apinatives.js +++ b/src/apinatives.js @@ -67,7 +67,7 @@ function InstantiateFunction(data, name) { kApiFunctionCache[serialNumber] = fun; var prototype = %GetTemplateField(data, kApiPrototypeTemplateOffset); fun.prototype = prototype ? Instantiate(prototype) : {}; - %AddProperty(fun.prototype, "constructor", fun, DONT_ENUM); + %SetProperty(fun.prototype, "constructor", fun, DONT_ENUM); var parent = %GetTemplateField(data, kApiParentTemplateOffset); if (parent) { var parent_fun = Instantiate(parent); diff --git a/src/array.js b/src/array.js index a733a0e..3b18b9d 100644 --- a/src/array.js +++ b/src/array.js @@ -907,7 +907,7 @@ function InstallFunctions(prototype, attributes, functions) { var key = functions[i]; var f = functions[i + 1]; %FunctionSetName(f, key); - %AddProperty(prototype, key, f, attributes); + %SetProperty(prototype, key, f, attributes); } } @@ -924,7 +924,7 @@ function UpdateFunctionLengths(lengths) { function SetupArray() { // Setup non-enumerable constructor property on the Array.prototype // object. - %AddProperty($Array.prototype, "constructor", $Array, DONT_ENUM); + %SetProperty($Array.prototype, "constructor", $Array, DONT_ENUM); // Setup non-enumerable functions of the Array.prototype object and // set their names. diff --git a/src/date-delay.js b/src/date-delay.js index ce0d487..0780a1b 100644 --- a/src/date-delay.js +++ b/src/date-delay.js @@ -959,7 +959,7 @@ function SetupDate() { )); // Setup non-enumerable constructor property of the Date prototype object. - %AddProperty($Date.prototype, "constructor", $Date, DONT_ENUM); + %SetProperty($Date.prototype, "constructor", $Date, DONT_ENUM); // Setup non-enumerable functions of the Date prototype object and // set their names. diff --git a/src/math.js b/src/math.js index 7d1c8d5..5b7c396 100644 --- a/src/math.js +++ b/src/math.js @@ -40,7 +40,7 @@ function MathConstructor() {} %FunctionSetInstanceClassName(MathConstructor, 'Math'); const $Math = new MathConstructor(); $Math.__proto__ = global.Object.prototype; -%AddProperty(global, "Math", $Math, DONT_ENUM); +%SetProperty(global, "Math", $Math, DONT_ENUM); // ECMA 262 - 15.8.2.1 function MathAbs(x) { @@ -126,17 +126,41 @@ function MathTan(x) { return %Math_tan(ToNumber(x)); } function SetupMath() { // Setup math constants. // ECMA-262, section 15.8.1.1. - %AddProperty($Math, "E", 2.7182818284590452354, DONT_ENUM | DONT_DELETE | READ_ONLY); + %SetProperty($Math, + "E", + 2.7182818284590452354, + DONT_ENUM | DONT_DELETE | READ_ONLY); // ECMA-262, section 15.8.1.2. - %AddProperty($Math, "LN10", 2.302585092994046, DONT_ENUM | DONT_DELETE | READ_ONLY); + %SetProperty($Math, + "LN10", + 2.302585092994046, + DONT_ENUM | DONT_DELETE | READ_ONLY); // ECMA-262, section 15.8.1.3. - %AddProperty($Math, "LN2", 0.6931471805599453, DONT_ENUM | DONT_DELETE | READ_ONLY); + %SetProperty($Math, + "LN2", + 0.6931471805599453, + DONT_ENUM | DONT_DELETE | READ_ONLY); // ECMA-262, section 15.8.1.4. - %AddProperty($Math, "LOG2E", 1.4426950408889634, DONT_ENUM | DONT_DELETE | READ_ONLY); - %AddProperty($Math, "LOG10E", 0.43429448190325176, DONT_ENUM | DONT_DELETE | READ_ONLY); - %AddProperty($Math, "PI", 3.1415926535897932, DONT_ENUM | DONT_DELETE | READ_ONLY); - %AddProperty($Math, "SQRT1_2", 0.7071067811865476, DONT_ENUM | DONT_DELETE | READ_ONLY); - %AddProperty($Math, "SQRT2", 1.4142135623730951, DONT_ENUM | DONT_DELETE | READ_ONLY); + %SetProperty($Math, + "LOG2E", + 1.4426950408889634, + DONT_ENUM | DONT_DELETE | READ_ONLY); + %SetProperty($Math, + "LOG10E", + 0.43429448190325176, + DONT_ENUM | DONT_DELETE | READ_ONLY); + %SetProperty($Math, + "PI", + 3.1415926535897932, + DONT_ENUM | DONT_DELETE | READ_ONLY); + %SetProperty($Math, + "SQRT1_2", + 0.7071067811865476, + DONT_ENUM | DONT_DELETE | READ_ONLY); + %SetProperty($Math, + "SQRT2", + 1.4142135623730951, + DONT_ENUM | DONT_DELETE | READ_ONLY); // Setup non-enumerable functions of the Math object and // set their names. diff --git a/src/messages.js b/src/messages.js index 62edbff..a6d9651 100644 --- a/src/messages.js +++ b/src/messages.js @@ -163,7 +163,7 @@ function MakeGenericError(constructor, type, args) { * Setup the Script function and constructor. */ %FunctionSetInstanceClassName(Script, 'Script'); -%AddProperty(Script.prototype, 'constructor', Script, DONT_ENUM); +%SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM); %SetCode(Script, function(x) { // Script objects can only be created by the VM. throw new $Error("Not supported"); @@ -633,7 +633,7 @@ function DefineError(f) { // effects when overwriting the error functions from // user code. var name = f.name; - %AddProperty(global, name, f, DONT_ENUM); + %SetProperty(global, name, f, DONT_ENUM); this['$' + name] = f; // Configure the error function. // prototype of 'Error' must be as default: new Object(). @@ -663,7 +663,7 @@ DefineError(function URIError() { }); // Setup extra properties of the Error.prototype object. $Error.prototype.message = ''; -%AddProperty($Error.prototype, 'toString', function toString() { +%SetProperty($Error.prototype, 'toString', function toString() { var type = this.type; if (type && !this.hasOwnProperty("message")) { return this.name + ": " + FormatMessage({ type: type, args: this.arguments }); diff --git a/src/regexp-delay.js b/src/regexp-delay.js index f1274fb..e15240a 100644 --- a/src/regexp-delay.js +++ b/src/regexp-delay.js @@ -290,7 +290,7 @@ var regExpInput = ""; function SetupRegExp() { %FunctionSetInstanceClassName($RegExp, 'RegExp'); %FunctionSetPrototype($RegExp, new $Object()); - %AddProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); + %SetProperty($RegExp.prototype, 'constructor', $RegExp, DONT_ENUM); %SetCode($RegExp, RegExpConstructor); InstallFunctions($RegExp.prototype, DONT_ENUM, $Array( diff --git a/src/runtime.cc b/src/runtime.cc index 1ac07c5..b574bfb 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -504,11 +504,14 @@ static Object* Runtime_InitializeVarGlobal(Arguments args) { // there, we add the property and take special precautions to always // add it as a local property even in case of callbacks in the // prototype chain (this rules out using SetProperty). + // We have IgnoreAttributesAndSetLocalProperty for this. LookupResult lookup; global->LocalLookup(*name, &lookup); if (!lookup.IsProperty()) { Object* value = (assign) ? args[1] : Heap::undefined_value(); - return global->AddProperty(*name, value, attributes); + return global->IgnoreAttributesAndSetLocalProperty(*name, + value, + attributes); } // Determine if this is a redeclaration of something read-only. @@ -568,10 +571,13 @@ static Object* Runtime_InitializeConstGlobal(Arguments args) { // there, we add the property and take special precautions to always // add it as a local property even in case of callbacks in the // prototype chain (this rules out using SetProperty). + // We use IgnoreAttributesAndSetLocalProperty instead LookupResult lookup; global->LocalLookup(*name, &lookup); if (!lookup.IsProperty()) { - return global->AddProperty(*name, *value, attributes); + return global->IgnoreAttributesAndSetLocalProperty(*name, + *value, + attributes); } // Determine if this is a redeclaration of something not @@ -1377,23 +1383,6 @@ Object* Runtime::SetObjectProperty(Handle object, } -static Object* Runtime_AddProperty(Arguments args) { - NoHandleAllocation ha; - ASSERT(args.length() == 4); - - CONVERT_CHECKED(JSObject, object, args[0]); - CONVERT_CHECKED(String, name, args[1]); - RUNTIME_ASSERT(!object->HasLocalProperty(name)); - CONVERT_CHECKED(Smi, attr_obj, args[3]); - - int attr = attr_obj->value(); - RUNTIME_ASSERT((attr & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - PropertyAttributes attributes = static_cast(attr); - - return object->AddProperty(name, args[2], attributes); -} - - static Object* Runtime_SetProperty(Arguments args) { NoHandleAllocation ha; RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); @@ -1406,10 +1395,11 @@ static Object* Runtime_SetProperty(Arguments args) { PropertyAttributes attributes = NONE; if (args.length() == 4) { CONVERT_CHECKED(Smi, value_obj, args[3]); - int value = value_obj->value(); + int unchecked_value = value_obj->value(); // Only attribute bits should be set. - ASSERT((value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); - attributes = static_cast(value); + RUNTIME_ASSERT( + (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); + attributes = static_cast(unchecked_value); } return Runtime::SetObjectProperty(object, key, value, attributes); } @@ -1419,12 +1409,22 @@ static Object* Runtime_SetProperty(Arguments args) { // exist, it will be added with attributes NONE. static Object* Runtime_IgnoreAttributesAndSetProperty(Arguments args) { NoHandleAllocation ha; - ASSERT(args.length() == 3); - + RUNTIME_ASSERT(args.length() == 3 || args.length() == 4); CONVERT_CHECKED(JSObject, object, args[0]); CONVERT_CHECKED(String, name, args[1]); + // Compute attributes. + PropertyAttributes attributes = NONE; + if (args.length() == 4) { + CONVERT_CHECKED(Smi, value_obj, args[3]); + int unchecked_value = value_obj->value(); + // Only attribute bits should be set. + RUNTIME_ASSERT( + (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); + attributes = static_cast(unchecked_value); + } - return object->IgnoreAttributesAndSetLocalProperty(name, args[2], NONE); + return object-> + IgnoreAttributesAndSetLocalProperty(name, args[2], attributes); } diff --git a/src/runtime.h b/src/runtime.h index 9349b81..b7c5717 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -39,7 +39,6 @@ namespace v8 { namespace internal { #define RUNTIME_FUNCTION_LIST_ALWAYS(F) \ /* Property access */ \ - F(AddProperty, 4) \ F(GetProperty, 2) \ F(DeleteProperty, 2) \ F(HasLocalProperty, 2) \ @@ -189,7 +188,7 @@ namespace v8 { namespace internal { F(EvalReceiver, 1) \ \ F(SetProperty, -1 /* 3 or 4 */) \ - F(IgnoreAttributesAndSetProperty, 3) \ + F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */) \ \ /* Arrays */ \ F(RemoveArrayHoles, 1) \ diff --git a/src/string.js b/src/string.js index 47dd7ba..bb12c01 100644 --- a/src/string.js +++ b/src/string.js @@ -784,7 +784,7 @@ ReplaceResultBuilder.prototype.generate = function() { function SetupString() { // Setup the constructor property on the String prototype object. - %AddProperty($String.prototype, "constructor", $String, DONT_ENUM); + %SetProperty($String.prototype, "constructor", $String, DONT_ENUM); // Setup the non-enumerable functions on the String object. diff --git a/src/v8natives.js b/src/v8natives.js index 9ba1db4..295a61b 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -41,15 +41,15 @@ // ECMA 262 - 15.1.1.1. -%AddProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); +%SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); // ECMA-262 - 15.1.1.2. -%AddProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); +%SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); // ECMA-262 - 15.1.1.3. -%AddProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); +%SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); // ECMA 262 - 15.1.4 @@ -57,18 +57,18 @@ function $isNaN(number) { var n = ToNumber(number); return NUMBER_IS_NAN(n); } -%AddProperty(global, "isNaN", $isNaN, DONT_ENUM); +%SetProperty(global, "isNaN", $isNaN, DONT_ENUM); // ECMA 262 - 15.1.5 function $isFinite(number) { return %NumberIsFinite(ToNumber(number)); } -%AddProperty(global, "isFinite", $isFinite, DONT_ENUM); +%SetProperty(global, "isFinite", $isFinite, DONT_ENUM); // ECMA-262 - 15.1.2.2 -%AddProperty(global, "parseInt", function(string, radix) { +%SetProperty(global, "parseInt", function(string, radix) { if (radix === void 0) { radix = 0; // Some people use parseInt instead of Math.floor. This @@ -93,7 +93,7 @@ function $isFinite(number) { // ECMA-262 - 15.1.2.3 -%AddProperty(global, "parseFloat", function(string) { +%SetProperty(global, "parseFloat", function(string) { return %StringParseFloat(ToString(string)); }, DONT_ENUM); @@ -112,14 +112,14 @@ function $isFinite(number) { %FunctionSetPrototype($Boolean, new $Boolean(false)); -%AddProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); +%SetProperty($Boolean.prototype, "constructor", $Boolean, DONT_ENUM); // ---------------------------------------------------------------------------- // Object $Object.prototype.constructor = $Object; -%AddProperty($Object.prototype, "toString", function() { +%SetProperty($Object.prototype, "toString", function() { var c = %ClassOf(this); // Hide Arguments from the outside. if (c === 'Arguments') c = 'Object'; @@ -128,32 +128,32 @@ $Object.prototype.constructor = $Object; // ECMA-262, section 15.2.4.3, page 84. -%AddProperty($Object.prototype, "toLocaleString", function() { +%SetProperty($Object.prototype, "toLocaleString", function() { return this.toString(); }, DONT_ENUM); // ECMA-262, section 15.2.4.4, page 85. -%AddProperty($Object.prototype, "valueOf", function() { +%SetProperty($Object.prototype, "valueOf", function() { return this; }, DONT_ENUM); // ECMA-262, section 15.2.4.5, page 85. -%AddProperty($Object.prototype, "hasOwnProperty", function(V) { +%SetProperty($Object.prototype, "hasOwnProperty", function(V) { return %HasLocalProperty(ToObject(this), ToString(V)); }, DONT_ENUM); // ECMA-262, section 15.2.4.6, page 85. -%AddProperty($Object.prototype, "isPrototypeOf", function(V) { +%SetProperty($Object.prototype, "isPrototypeOf", function(V) { if (!IS_OBJECT(V) && !IS_FUNCTION(V)) return false; return %IsInPrototypeChain(this, V); }, DONT_ENUM); // ECMA-262, section 15.2.4.6, page 85. -%AddProperty($Object.prototype, "propertyIsEnumerable", function(V) { +%SetProperty($Object.prototype, "propertyIsEnumerable", function(V) { if (this == null) return false; if (!IS_OBJECT(this) && !IS_FUNCTION(this)) return false; return %IsPropertyEnumerable(this, ToString(V)); @@ -161,29 +161,43 @@ $Object.prototype.constructor = $Object; // Extensions for providing property getters and setters. -%AddProperty($Object.prototype, "__defineGetter__", function(name, fun) { - if (this == null) throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); - if (!IS_FUNCTION(fun)) throw new $TypeError('Object.prototype.__defineGetter__: Expecting function'); +%SetProperty($Object.prototype, "__defineGetter__", function(name, fun) { + if (this == null) { + throw new $TypeError('Object.prototype.__defineGetter__: this is Null'); + } + if (!IS_FUNCTION(fun)) { + throw new $TypeError( + 'Object.prototype.__defineGetter__: Expecting function'); + } return %DefineAccessor(ToObject(this), ToString(name), GETTER, fun); }, DONT_ENUM); -%AddProperty($Object.prototype, "__lookupGetter__", function(name) { - if (this == null) throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); +%SetProperty($Object.prototype, "__lookupGetter__", function(name) { + if (this == null) { + throw new $TypeError('Object.prototype.__lookupGetter__: this is Null'); + } return %LookupAccessor(ToObject(this), ToString(name), GETTER); }, DONT_ENUM); -%AddProperty($Object.prototype, "__defineSetter__", function(name, fun) { - if (this == null) throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); - if (!IS_FUNCTION(fun)) throw new $TypeError('Object.prototype.__defineSetter__: Expecting function'); +%SetProperty($Object.prototype, "__defineSetter__", function(name, fun) { + if (this == null) { + throw new $TypeError('Object.prototype.__defineSetter__: this is Null'); + } + if (!IS_FUNCTION(fun)) { + throw new $TypeError( + 'Object.prototype.__defineSetter__: Expecting function'); + } return %DefineAccessor(ToObject(this), ToString(name), SETTER, fun); }, DONT_ENUM); -%AddProperty($Object.prototype, "__lookupSetter__", function(name) { - if (this == null) throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); +%SetProperty($Object.prototype, "__lookupSetter__", function(name) { + if (this == null) { + throw new $TypeError('Object.prototype.__lookupSetter__: this is Null'); + } return %LookupAccessor(ToObject(this), ToString(name), SETTER); }, DONT_ENUM); @@ -202,7 +216,7 @@ $Object.prototype.constructor = $Object; // ---------------------------------------------------------------------------- // Global stuff... -%AddProperty(global, "eval", function(x) { +%SetProperty(global, "eval", function(x) { if (!IS_STRING(x)) return x; var f = %CompileString(x, 0, true); @@ -213,7 +227,7 @@ $Object.prototype.constructor = $Object; // execScript for IE compatibility. -%AddProperty(global, "execScript", function(expr, lang) { +%SetProperty(global, "execScript", function(expr, lang) { // NOTE: We don't care about the character casing. if (!lang || /javascript/i.test(lang)) { var f = %CompileString(ToString(expr), 0, false); @@ -226,7 +240,7 @@ $Object.prototype.constructor = $Object; // ---------------------------------------------------------------------------- // Boolean -%AddProperty($Boolean.prototype, "toString", function() { +%SetProperty($Boolean.prototype, "toString", function() { // NOTE: Both Boolean objects and values can enter here as // 'this'. This is not as dictated by ECMA-262. if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean') @@ -235,7 +249,7 @@ $Object.prototype.constructor = $Object; }, DONT_ENUM); -%AddProperty($Boolean.prototype, "valueOf", function() { +%SetProperty($Boolean.prototype, "valueOf", function() { // NOTE: Both Boolean objects and values can enter here as // 'this'. This is not as dictated by ECMA-262. if (!IS_BOOLEAN(this) && %ClassOf(this) !== 'Boolean') @@ -259,25 +273,34 @@ $Object.prototype.constructor = $Object; %FunctionSetPrototype($Number, new $Number(0)); -%AddProperty($Number.prototype, "constructor", $Number, DONT_ENUM); +%SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); // ECMA-262 section 15.7.3.1. -%AddProperty($Number, "MAX_VALUE", 1.7976931348623157e+308, DONT_ENUM | DONT_DELETE | READ_ONLY); +%SetProperty($Number, + "MAX_VALUE", + 1.7976931348623157e+308, + DONT_ENUM | DONT_DELETE | READ_ONLY); // ECMA-262 section 15.7.3.2. -%AddProperty($Number, "MIN_VALUE", 5e-324, DONT_ENUM | DONT_DELETE | READ_ONLY); +%SetProperty($Number, "MIN_VALUE", 5e-324, DONT_ENUM | DONT_DELETE | READ_ONLY); // ECMA-262 section 15.7.3.3. -%AddProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); +%SetProperty($Number, "NaN", $NaN, DONT_ENUM | DONT_DELETE | READ_ONLY); // ECMA-262 section 15.7.3.4. -%AddProperty($Number, "NEGATIVE_INFINITY", -1/0, DONT_ENUM | DONT_DELETE | READ_ONLY); +%SetProperty($Number, + "NEGATIVE_INFINITY", + -1/0, + DONT_ENUM | DONT_DELETE | READ_ONLY); // ECMA-262 section 15.7.3.5. -%AddProperty($Number, "POSITIVE_INFINITY", 1/0, DONT_ENUM | DONT_DELETE | READ_ONLY); +%SetProperty($Number, + "POSITIVE_INFINITY", + 1/0, + DONT_ENUM | DONT_DELETE | READ_ONLY); // ECMA-262 section 15.7.4.2. -%AddProperty($Number.prototype, "toString", function(radix) { +%SetProperty($Number.prototype, "toString", function(radix) { // NOTE: Both Number objects and values can enter here as // 'this'. This is not as dictated by ECMA-262. var number = this; @@ -303,13 +326,13 @@ $Object.prototype.constructor = $Object; // ECMA-262 section 15.7.4.3 -%AddProperty($Number.prototype, "toLocaleString", function() { +%SetProperty($Number.prototype, "toLocaleString", function() { return this.toString(); }, DONT_ENUM); // ECMA-262 section 15.7.4.4 -%AddProperty($Number.prototype, "valueOf", function() { +%SetProperty($Number.prototype, "valueOf", function() { // NOTE: Both Number objects and values can enter here as // 'this'. This is not as dictated by ECMA-262. if (!IS_NUMBER(this) && %ClassOf(this) !== 'Number') @@ -319,7 +342,7 @@ $Object.prototype.constructor = $Object; // ECMA-262 section 15.7.4.5 -%AddProperty($Number.prototype, "toFixed", function(fractionDigits) { +%SetProperty($Number.prototype, "toFixed", function(fractionDigits) { var f = TO_INTEGER(fractionDigits); if (f < 0 || f > 20) { throw new $RangeError("toFixed() digits argument must be between 0 and 20"); @@ -330,7 +353,7 @@ $Object.prototype.constructor = $Object; // ECMA-262 section 15.7.4.6 -%AddProperty($Number.prototype, "toExponential", function(fractionDigits) { +%SetProperty($Number.prototype, "toExponential", function(fractionDigits) { var f = -1; if (!IS_UNDEFINED(fractionDigits)) { f = TO_INTEGER(fractionDigits); @@ -344,7 +367,7 @@ $Object.prototype.constructor = $Object; // ECMA-262 section 15.7.4.7 -%AddProperty($Number.prototype, "toPrecision", function(precision) { +%SetProperty($Number.prototype, "toPrecision", function(precision) { if (IS_UNDEFINED(precision)) return ToString(%_ValueOf(this)); var p = TO_INTEGER(precision); if (p < 1 || p > 21) { @@ -389,7 +412,7 @@ function FunctionSourceString(func) { } -%AddProperty($Function.prototype, "toString", function() { +%SetProperty($Function.prototype, "toString", function() { return FunctionSourceString(this); }, DONT_ENUM); diff --git a/test/mjsunit/regress/regress-1199637.js b/test/mjsunit/regress/regress-1199637.js index 2c97f9a..d9116c1 100644 --- a/test/mjsunit/regress/regress-1199637.js +++ b/test/mjsunit/regress/regress-1199637.js @@ -34,43 +34,43 @@ const NONE = 0; const READ_ONLY = 1; // Use DeclareGlobal... -%AddProperty(this.__proto__, "a", "1234", NONE); +%SetProperty(this.__proto__, "a", "1234", NONE); assertEquals(1234, a); eval("var a = 5678;"); assertEquals(5678, a); -%AddProperty(this.__proto__, "b", "1234", NONE); +%SetProperty(this.__proto__, "b", "1234", NONE); assertEquals(1234, b); eval("const b = 5678;"); assertEquals(5678, b); -%AddProperty(this.__proto__, "c", "1234", READ_ONLY); +%SetProperty(this.__proto__, "c", "1234", READ_ONLY); assertEquals(1234, c); eval("var c = 5678;"); assertEquals(5678, c); -%AddProperty(this.__proto__, "d", "1234", READ_ONLY); +%SetProperty(this.__proto__, "d", "1234", READ_ONLY); assertEquals(1234, d); eval("const d = 5678;"); assertEquals(5678, d); // Use DeclareContextSlot... -%AddProperty(this.__proto__, "x", "1234", NONE); +%SetProperty(this.__proto__, "x", "1234", NONE); assertEquals(1234, x); eval("with({}) { var x = 5678; }"); assertEquals(5678, x); -%AddProperty(this.__proto__, "y", "1234", NONE); +%SetProperty(this.__proto__, "y", "1234", NONE); assertEquals(1234, y); eval("with({}) { const y = 5678; }"); assertEquals(5678, y); -%AddProperty(this.__proto__, "z", "1234", READ_ONLY); +%SetProperty(this.__proto__, "z", "1234", READ_ONLY); assertEquals(1234, z); eval("with({}) { var z = 5678; }"); assertEquals(5678, z); -%AddProperty(this.__proto__, "w", "1234", READ_ONLY); +%SetProperty(this.__proto__, "w", "1234", READ_ONLY); assertEquals(1234, w); eval("with({}) { const w = 5678; }"); assertEquals(5678, w); -- 2.7.4