Commit d2a8454d authored by whessev8's avatar whessev8

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
parent fbd7acf5
......@@ -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);
......
......@@ -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.
......
......@@ -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.
......
......@@ -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.
......
......@@ -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 });
......
......@@ -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(
......
......@@ -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> 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<PropertyAttributes>(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<PropertyAttributes>(value);
RUNTIME_ASSERT(
(unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
attributes = static_cast<PropertyAttributes>(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<PropertyAttributes>(unchecked_value);
}
return object->IgnoreAttributesAndSetLocalProperty(name, args[2], NONE);
return object->
IgnoreAttributesAndSetLocalProperty(name, args[2], attributes);
}
......
......@@ -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) \
......
......@@ -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.
......
This diff is collapsed.
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment