Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Unified Diff: src/runtime.cc

Issue 351853005: Split SetProperty(...attributes, strictmode) into AddProperty(...attributes) and SetProperty(...… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime.h ('k') | src/scopeinfo.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 3cb6fe20a20b752b42e042f33585459df27ef8aa..f543c96b5f37d3784533b37105d8f9204a01cf68 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -273,8 +273,12 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
if (key->IsInternalizedString()) {
if (Handle<String>::cast(key)->AsArrayIndex(&element_index)) {
// Array index as string (uint32).
- maybe_result = JSObject::SetOwnElement(
- boilerplate, element_index, value, SLOPPY);
+ if (value->IsUninitialized()) {
+ maybe_result = value;
+ } else {
+ maybe_result = JSObject::SetOwnElement(
+ boilerplate, element_index, value, SLOPPY);
+ }
} else {
Handle<String> name(String::cast(*key));
ASSERT(!name->AsArrayIndex(&element_index));
@@ -284,8 +288,12 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
}
} else if (key->ToArrayIndex(&element_index)) {
// Array index (uint32).
- maybe_result = JSObject::SetOwnElement(
- boilerplate, element_index, value, SLOPPY);
+ if (value->IsUninitialized()) {
+ maybe_result = value;
+ } else {
+ maybe_result = JSObject::SetOwnElement(
+ boilerplate, element_index, value, SLOPPY);
+ }
} else {
// Non-uint32 number.
ASSERT(key->IsNumber());
@@ -2095,37 +2103,6 @@ RUNTIME_FUNCTION(Runtime_EnableAccessChecks) {
}
-// Transform getter or setter into something DefineAccessor can handle.
-static Handle<Object> InstantiateAccessorComponent(Isolate* isolate,
- Handle<Object> component) {
- if (component->IsUndefined()) return isolate->factory()->null_value();
- Handle<FunctionTemplateInfo> info =
- Handle<FunctionTemplateInfo>::cast(component);
- return Utils::OpenHandle(*Utils::ToLocal(info)->GetFunction());
-}
-
-
-RUNTIME_FUNCTION(Runtime_SetAccessorProperty) {
- HandleScope scope(isolate);
- ASSERT(args.length() == 5);
- CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
- CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
- CONVERT_ARG_HANDLE_CHECKED(Object, getter, 2);
- CONVERT_ARG_HANDLE_CHECKED(Object, setter, 3);
- CONVERT_SMI_ARG_CHECKED(attribute, 4);
- RUNTIME_ASSERT(getter->IsUndefined() || getter->IsFunctionTemplateInfo());
- RUNTIME_ASSERT(setter->IsUndefined() || setter->IsFunctionTemplateInfo());
- RUNTIME_ASSERT(PropertyDetails::AttributesField::is_valid(
- static_cast<PropertyAttributes>(attribute)));
- JSObject::DefineAccessor(object,
- name,
- InstantiateAccessorComponent(isolate, getter),
- InstantiateAccessorComponent(isolate, setter),
- static_cast<PropertyAttributes>(attribute));
- return isolate->heap()->undefined_value();
-}
-
-
static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) {
HandleScope scope(isolate);
Handle<Object> args[1] = { name };
@@ -5037,7 +5014,7 @@ static bool IsValidAccessor(Handle<Object> obj) {
// Steps 9c & 12 - replace an existing data property with an accessor property.
// Step 12 - update an existing accessor property with an accessor or generic
// descriptor.
-RUNTIME_FUNCTION(Runtime_DefineOrRedefineAccessorProperty) {
+RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) {
HandleScope scope(isolate);
ASSERT(args.length() == 5);
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
@@ -5066,7 +5043,7 @@ RUNTIME_FUNCTION(Runtime_DefineOrRedefineAccessorProperty) {
// Steps 9b & 12 - replace an existing accessor property with a data property.
// Step 12 - update an existing data property with a data or generic
// descriptor.
-RUNTIME_FUNCTION(Runtime_DefineOrRedefineDataProperty) {
+RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) {
HandleScope scope(isolate);
ASSERT(args.length() == 4);
CONVERT_ARG_HANDLE_CHECKED(JSObject, js_object, 0);
@@ -5124,7 +5101,7 @@ RUNTIME_FUNCTION(Runtime_DefineOrRedefineDataProperty) {
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
- Runtime::ForceSetObjectProperty(
+ Runtime::DefineObjectProperty(
js_object, name, obj_value, attr,
JSReceiver::CERTAINLY_NOT_STORE_FROM_KEYED));
return *result;
@@ -5145,10 +5122,8 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
Handle<Object> object,
Handle<Object> key,
Handle<Object> value,
- PropertyAttributes attr,
- StrictMode strict_mode) {
- SetPropertyMode set_mode = attr == NONE ? SET_PROPERTY : DEFINE_PROPERTY;
-
+ StrictMode strict_mode,
+ PropertyAttributes attrs) {
if (object->IsUndefined() || object->IsNull()) {
Handle<Object> args[2] = { key, object };
Handle<Object> error =
@@ -5167,8 +5142,7 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
}
Handle<Name> name = Handle<Name>::cast(name_object);
return JSReceiver::SetProperty(Handle<JSProxy>::cast(object), name, value,
- attr,
- strict_mode);
+ attrs, strict_mode);
}
// If the object isn't a JavaScript object, we ignore the store.
@@ -5200,7 +5174,7 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
}
MaybeHandle<Object> result = JSObject::SetElement(
- js_object, index, value, attr, strict_mode, true, set_mode);
+ js_object, index, value, attrs, strict_mode, true, SET_PROPERTY);
JSObject::ValidateElements(js_object);
return result.is_null() ? result : value;
@@ -5215,11 +5189,12 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
isolate, value, Execution::ToNumber(isolate, value), Object);
}
}
- return JSObject::SetElement(js_object, index, value, attr,
- strict_mode, true, set_mode);
+ return JSObject::SetElement(js_object, index, value, attrs,
+ strict_mode, true, SET_PROPERTY);
} else {
if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
- return JSReceiver::SetProperty(js_object, name, value, attr, strict_mode);
+ return JSReceiver::SetProperty(
+ js_object, name, value, attrs, strict_mode);
}
}
@@ -5230,15 +5205,15 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
Handle<String> name = Handle<String>::cast(converted);
if (name->AsArrayIndex(&index)) {
- return JSObject::SetElement(js_object, index, value, attr,
- strict_mode, true, set_mode);
+ return JSObject::SetElement(js_object, index, value, attrs,
+ strict_mode, true, SET_PROPERTY);
} else {
- return JSReceiver::SetProperty(js_object, name, value, attr, strict_mode);
+ return JSReceiver::SetProperty(js_object, name, value, attrs, strict_mode);
}
}
-MaybeHandle<Object> Runtime::ForceSetObjectProperty(
+MaybeHandle<Object> Runtime::DefineObjectProperty(
Handle<JSObject> js_object,
Handle<Object> key,
Handle<Object> value,
@@ -5343,11 +5318,11 @@ RUNTIME_FUNCTION(Runtime_SetHiddenProperty) {
}
-RUNTIME_FUNCTION(Runtime_SetProperty) {
+RUNTIME_FUNCTION(Runtime_AddProperty) {
HandleScope scope(isolate);
- RUNTIME_ASSERT(args.length() == 4 || args.length() == 5);
+ RUNTIME_ASSERT(args.length() == 4);
- CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
CONVERT_SMI_ARG_CHECKED(unchecked_attributes, 3);
@@ -5357,17 +5332,41 @@ RUNTIME_FUNCTION(Runtime_SetProperty) {
PropertyAttributes attributes =
static_cast<PropertyAttributes>(unchecked_attributes);
- StrictMode strict_mode = SLOPPY;
- if (args.length() == 5) {
- CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode_arg, 4);
- strict_mode = strict_mode_arg;
+#ifdef DEBUG
+ if (key->IsName()) {
+ LookupIterator it(object, Handle<Name>::cast(key),
+ LookupIterator::CHECK_OWN);
+ JSReceiver::GetPropertyAttributes(&it);
+ RUNTIME_ASSERT(!it.IsFound());
+ } else {
+ uint32_t index = 0;
+ RUNTIME_ASSERT(key->ToArrayIndex(&index));
+ RUNTIME_ASSERT(!JSReceiver::HasOwnElement(object, index));
}
+#endif
Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result,
- Runtime::SetObjectProperty(
- isolate, object, key, value, attributes, strict_mode));
+ Runtime::DefineObjectProperty(object, key, value, attributes));
+ return *result;
+}
+
+
+RUNTIME_FUNCTION(Runtime_SetProperty) {
+ HandleScope scope(isolate);
+ RUNTIME_ASSERT(args.length() == 4);
+
+ CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
+ CONVERT_ARG_HANDLE_CHECKED(Object, key, 1);
+ CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
+ CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode_arg, 3);
+ StrictMode strict_mode = strict_mode_arg;
+
+ Handle<Object> result;
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
+ isolate, result,
+ Runtime::SetObjectProperty(isolate, object, key, value, strict_mode));
return *result;
}
@@ -5521,32 +5520,6 @@ RUNTIME_FUNCTION(Runtime_DebugPromiseHandleEpilogue) {
}
-// Set an own property, even if it is READ_ONLY. If the property does not
-// exist, it will be added with attributes NONE.
-RUNTIME_FUNCTION(Runtime_IgnoreAttributesAndSetProperty) {
- HandleScope scope(isolate);
- RUNTIME_ASSERT(args.length() == 3 || args.length() == 4);
- CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
- CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
- CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
- // Compute attributes.
- PropertyAttributes attributes = NONE;
- if (args.length() == 4) {
- CONVERT_SMI_ARG_CHECKED(unchecked_value, 3);
- // Only attribute bits should be set.
- RUNTIME_ASSERT(
- (unchecked_value & ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0);
- attributes = static_cast<PropertyAttributes>(unchecked_value);
- }
- Handle<Object> result;
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
- isolate, result,
- JSObject::SetOwnPropertyIgnoreAttributes(
- object, name, value, attributes));
- return *result;
-}
-
-
RUNTIME_FUNCTION(Runtime_DeleteProperty) {
HandleScope scope(isolate);
ASSERT(args.length() == 3);
@@ -11404,7 +11377,7 @@ static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector(
RETURN_ON_EXCEPTION(
isolate,
- Runtime::SetObjectProperty(isolate, target, name, value, NONE, SLOPPY),
+ Runtime::SetObjectProperty(isolate, target, name, value, SLOPPY),
JSObject);
}
@@ -11417,7 +11390,7 @@ static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector(
RETURN_ON_EXCEPTION(
isolate,
- Runtime::SetObjectProperty(isolate, target, name, value, NONE, SLOPPY),
+ Runtime::SetObjectProperty(isolate, target, name, value, SLOPPY),
JSObject);
}
@@ -11506,8 +11479,7 @@ MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeLocalContext(
isolate, value, Object::GetPropertyOrElement(ext, key), JSObject);
RETURN_ON_EXCEPTION(
isolate,
- Runtime::SetObjectProperty(
- isolate, target, key, value, NONE, SLOPPY),
+ Runtime::SetObjectProperty(isolate, target, key, value, SLOPPY),
JSObject);
}
}
@@ -11612,7 +11584,7 @@ static bool SetLocalVariableValue(Isolate* isolate,
// We don't expect this to do anything except replacing
// property value.
Runtime::SetObjectProperty(isolate, ext, variable_name, new_value,
- NONE, SLOPPY).Assert();
+ SLOPPY).Assert();
return true;
}
}
@@ -11663,8 +11635,7 @@ MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeClosure(
isolate, value, Object::GetPropertyOrElement(ext, key), JSObject);
RETURN_ON_EXCEPTION(
isolate,
- Runtime::SetObjectProperty(
- isolate, closure_scope, key, value, NONE, SLOPPY),
+ Runtime::DefineObjectProperty(closure_scope, key, value, NONE),
JSObject);
}
}
@@ -11695,8 +11666,8 @@ static bool SetClosureVariableValue(Isolate* isolate,
Handle<JSObject> ext(JSObject::cast(context->extension()));
if (JSReceiver::HasProperty(ext, variable_name)) {
// We don't expect this to do anything except replacing property value.
- Runtime::SetObjectProperty(isolate, ext, variable_name, new_value,
- NONE, SLOPPY).Assert();
+ Runtime::DefineObjectProperty(
+ ext, variable_name, new_value, NONE).Assert();
return true;
}
}
@@ -11718,8 +11689,7 @@ MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeCatchScope(
isolate->factory()->NewJSObject(isolate->object_function());
RETURN_ON_EXCEPTION(
isolate,
- Runtime::SetObjectProperty(isolate, catch_scope, name, thrown_object,
- NONE, SLOPPY),
+ Runtime::DefineObjectProperty(catch_scope, name, thrown_object, NONE),
JSObject);
return catch_scope;
}
@@ -12782,8 +12752,7 @@ MUST_USE_RESULT static MaybeHandle<JSObject> MaterializeArgumentsObject(
Handle<String> arguments_str = isolate->factory()->arguments_string();
RETURN_ON_EXCEPTION(
isolate,
- Runtime::SetObjectProperty(
- isolate, target, arguments_str, arguments, ::NONE, SLOPPY),
+ Runtime::DefineObjectProperty(target, arguments_str, arguments, NONE),
JSObject);
return target;
}
« no previous file with comments | « src/runtime.h ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698