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

Unified Diff: src/runtime/runtime-object.cc

Issue 1180943002: Reland of Replace SetObjectProperty / DefineObjectProperty with less powerful alternatives where re… (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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/runtime-debug.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime/runtime-object.cc
diff --git a/src/runtime/runtime-object.cc b/src/runtime/runtime-object.cc
index 703bbedabee3528dd1355f756822c0eb1ac5ae54..99aebda67bd3b2fb4342d867ea959a0e54805325 100644
--- a/src/runtime/runtime-object.cc
+++ b/src/runtime/runtime-object.cc
@@ -92,98 +92,13 @@ MaybeHandle<Object> Runtime::SetObjectProperty(Isolate* isolate,
Object);
}
- if (object->IsJSProxy()) {
- Handle<Object> name_object;
- if (key->IsSymbol()) {
- name_object = key;
- } else {
- ASSIGN_RETURN_ON_EXCEPTION(isolate, name_object,
- Execution::ToString(isolate, key), Object);
- }
- Handle<Name> name = Handle<Name>::cast(name_object);
- return Object::SetProperty(Handle<JSProxy>::cast(object), name, value,
- language_mode);
- }
-
- // Check if the given key is an array index.
- uint32_t index = 0;
- if (key->ToArrayIndex(&index)) {
- // TODO(verwaest): Support non-JSObject receivers.
- if (!object->IsJSObject()) return value;
- Handle<JSObject> js_object = Handle<JSObject>::cast(object);
-
- // In Firefox/SpiderMonkey, Safari and Opera you can access the characters
- // of a string using [] notation. We need to support this too in
- // JavaScript.
- // In the case of a String object we just need to redirect the assignment to
- // the underlying string if the index is in range. Since the underlying
- // string does nothing with the assignment then we can ignore such
- // assignments.
- if (js_object->IsStringObjectWithCharacterAt(index)) {
- return value;
- }
-
- JSObject::ValidateElements(js_object);
- if (js_object->HasExternalArrayElements() ||
- js_object->HasFixedTypedArrayElements()) {
- if (!value->IsNumber() && !value->IsUndefined()) {
- ASSIGN_RETURN_ON_EXCEPTION(isolate, value,
- Execution::ToNumber(isolate, value), Object);
- }
- }
-
- MaybeHandle<Object> result =
- JSObject::SetElement(js_object, index, value, language_mode);
- JSObject::ValidateElements(js_object);
-
- return result.is_null() ? result : value;
- }
-
- if (key->IsName()) {
- Handle<Name> name = Handle<Name>::cast(key);
- if (name->AsArrayIndex(&index)) {
- // TODO(verwaest): Support non-JSObject receivers.
- if (!object->IsJSObject()) return value;
- Handle<JSObject> js_object = Handle<JSObject>::cast(object);
- if (js_object->HasExternalArrayElements()) {
- if (!value->IsNumber() && !value->IsUndefined()) {
- ASSIGN_RETURN_ON_EXCEPTION(
- isolate, value, Execution::ToNumber(isolate, value), Object);
- }
- }
- return JSObject::SetElement(js_object, index, value, language_mode);
- } else {
- if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
- return Object::SetProperty(object, name, value, language_mode);
- }
- }
-
- // Call-back into JavaScript to convert the key to a string.
- Handle<Object> converted;
- ASSIGN_RETURN_ON_EXCEPTION(isolate, converted,
- Execution::ToString(isolate, key), Object);
- Handle<String> name = Handle<String>::cast(converted);
-
- if (name->AsArrayIndex(&index)) {
- // TODO(verwaest): Support non-JSObject receivers.
- if (!object->IsJSObject()) return value;
- Handle<JSObject> js_object = Handle<JSObject>::cast(object);
- return JSObject::SetElement(js_object, index, value, language_mode);
- }
- return Object::SetProperty(object, name, value, language_mode);
-}
-
-
-MaybeHandle<Object> Runtime::DefineObjectProperty(
- Handle<JSObject> js_object, Handle<Object> key, Handle<Object> value,
- PropertyAttributes attrs,
- JSObject::ExecutableAccessorInfoHandling handling) {
- Isolate* isolate = js_object->GetIsolate();
// Check if the given key is an array index.
uint32_t index = 0;
if (key->ToArrayIndex(&index)) {
- return JSObject::SetOwnElementIgnoreAttributes(js_object, index, value,
- attrs, handling);
+ // TODO(verwaest): Support other objects as well.
+ if (!object->IsJSReceiver()) return value;
+ return JSReceiver::SetElement(Handle<JSReceiver>::cast(object), index,
+ value, language_mode);
}
Handle<Name> name;
@@ -198,13 +113,12 @@ MaybeHandle<Object> Runtime::DefineObjectProperty(
}
if (name->AsArrayIndex(&index)) {
- return JSObject::SetOwnElementIgnoreAttributes(js_object, index, value,
- attrs, handling);
- } else {
- if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
- return JSObject::SetOwnPropertyIgnoreAttributes(js_object, name, value,
- attrs, handling);
+ // TODO(verwaest): Support other objects as well.
+ if (!object->IsJSReceiver()) return value;
+ return JSReceiver::SetElement(Handle<JSReceiver>::cast(object), index,
+ value, language_mode);
}
+ return Object::SetProperty(object, name, value, language_mode);
}
@@ -1355,24 +1269,28 @@ RUNTIME_FUNCTION(Runtime_DefineAccessorPropertyUnchecked) {
RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) {
HandleScope scope(isolate);
DCHECK(args.length() == 4);
- CONVERT_ARG_HANDLE_CHECKED(JSObject, js_object, 0);
+ CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0);
CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
- CONVERT_ARG_HANDLE_CHECKED(Object, obj_value, 2);
+ CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3);
- LookupIterator it(js_object, name, LookupIterator::OWN_SKIP_INTERCEPTOR);
- if (it.IsFound() && it.state() == LookupIterator::ACCESS_CHECK) {
- if (!isolate->MayAccess(js_object)) {
- return isolate->heap()->undefined_value();
- }
- it.Next();
+ uint32_t index = 0;
+ LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR;
+ LookupIterator it = name->AsArrayIndex(&index)
+ ? LookupIterator(isolate, object, index, c)
+ : LookupIterator(object, name, c);
+ if (it.state() == LookupIterator::ACCESS_CHECK && !it.HasAccess()) {
+ return isolate->heap()->undefined_value();
}
Handle<Object> result;
- ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
- isolate, result,
- Runtime::DefineObjectProperty(js_object, name, obj_value, attrs,
- JSObject::DONT_FORCE_FIELD));
+ MaybeHandle<Object> maybe_result =
+ it.IsElement()
+ ? JSObject::SetOwnElementIgnoreAttributes(object, index, value, attrs,
+ JSObject::DONT_FORCE_FIELD)
+ : JSObject::SetOwnPropertyIgnoreAttributes(
+ object, name, value, attrs, JSObject::DONT_FORCE_FIELD);
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, maybe_result);
return *result;
}
@@ -1382,8 +1300,8 @@ RUNTIME_FUNCTION(Runtime_GetDataProperty) {
HandleScope scope(isolate);
DCHECK(args.length() == 2);
CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0);
- CONVERT_ARG_HANDLE_CHECKED(Name, key, 1);
- return *JSReceiver::GetDataProperty(object, key);
+ CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);
+ return *JSReceiver::GetDataProperty(object, name);
}
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698