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

Unified Diff: src/api.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 | « no previous file | src/api-natives.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index c405b875385e4e1ad8235d6148b97f66f2bd7ac2..7f094faa4ce68d9f62879ed91f0a74618db1a274 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -3535,9 +3535,9 @@ Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
if (it.IsFound() && !it.IsConfigurable()) return Just(false);
- has_pending_exception =
- i::Runtime::DefineObjectProperty(self, key_obj, value_obj, NONE,
- i::JSObject::DONT_FORCE_FIELD).is_null();
+ has_pending_exception = i::JSObject::SetOwnPropertyIgnoreAttributes(
+ self, key_obj, value_obj, NONE,
+ i::JSObject::DONT_FORCE_FIELD).is_null();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return Just(true);
}
@@ -3574,10 +3574,9 @@ Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
return Just(false);
}
- has_pending_exception =
- i::Runtime::DefineObjectProperty(
- self, isolate->factory()->Uint32ToString(index), value_obj, NONE,
- i::JSObject::DONT_FORCE_FIELD).is_null();
+ has_pending_exception = i::JSObject::SetOwnElementIgnoreAttributes(
+ self, index, value_obj, NONE,
+ i::JSObject::DONT_FORCE_FIELD).is_null();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return Just(true);
}
@@ -3615,6 +3614,34 @@ Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context,
}
+MUST_USE_RESULT
+static i::MaybeHandle<i::Object> DefineObjectProperty(
+ i::Handle<i::JSObject> js_object, i::Handle<i::Object> key,
+ i::Handle<i::Object> value, PropertyAttributes attrs) {
+ i::Isolate* isolate = js_object->GetIsolate();
+ // Check if the given key is an array index.
+ uint32_t index = 0;
+ if (key->ToArrayIndex(&index)) {
+ return i::JSObject::SetOwnElementIgnoreAttributes(js_object, index, value,
+ attrs);
+ }
+
+ i::Handle<i::Name> name;
+ if (key->IsName()) {
+ name = i::Handle<i::Name>::cast(key);
+ } else {
+ // Call-back into JavaScript to convert the key to a string.
+ i::Handle<i::Object> converted;
+ ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, converted,
+ i::Execution::ToString(isolate, key),
+ i::MaybeHandle<i::Object>());
+ name = i::Handle<i::String>::cast(converted);
+ }
+
+ return i::JSObject::DefinePropertyOrElement(js_object, name, value, attrs);
+}
+
+
Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context,
v8::Local<Value> key, v8::Local<Value> value,
v8::PropertyAttribute attribs) {
@@ -3622,11 +3649,9 @@ Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context,
auto self = Utils::OpenHandle(this);
auto key_obj = Utils::OpenHandle(*key);
auto value_obj = Utils::OpenHandle(*value);
- has_pending_exception = i::Runtime::DefineObjectProperty(
- self,
- key_obj,
- value_obj,
- static_cast<PropertyAttributes>(attribs)).is_null();
+ has_pending_exception =
+ DefineObjectProperty(self, key_obj, value_obj,
+ static_cast<PropertyAttributes>(attribs)).is_null();
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
return Just(true);
}
@@ -3642,9 +3667,8 @@ bool v8::Object::ForceSet(v8::Handle<Value> key, v8::Handle<Value> value,
i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
has_pending_exception =
- i::Runtime::DefineObjectProperty(self, key_obj, value_obj,
- static_cast<PropertyAttributes>(attribs))
- .is_null();
+ DefineObjectProperty(self, key_obj, value_obj,
+ static_cast<PropertyAttributes>(attribs)).is_null();
EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, false);
return true;
}
« no previous file with comments | « no previous file | src/api-natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698