Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 808def3b0fad215568c02b494e8faac6b5249c5b..4b506695d547f099b77e7f2da91184d70a588ec8 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -3461,6 +3461,113 @@ bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
} |
+Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, |
+ v8::Local<Name> key, |
+ v8::Local<Value> value) { |
+ PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", |
Toon Verwaest
2015/05/26 19:40:55
It seems like this is more of a DefineDataProperty
jochen (gone - plz use gerrit)
2015/05/27 07:28:30
it's the name of the JS method.
|
+ bool); |
+ auto self = Utils::OpenHandle(this); |
Toon Verwaest
2015/05/26 19:40:55
Note that I'm in the process of merging all named
|
+ auto key_obj = Utils::OpenHandle(*key); |
+ auto value_obj = Utils::OpenHandle(*value); |
+ if (!self->IsExtensible()) return Just(false); |
+ |
+ uint32_t index = 0; |
+ if (key_obj->AsArrayIndex(&index)) { |
+ return CreateDataProperty(context, index, value); |
+ } |
+ |
+ // Special case for Array.length. |
jochen (gone - plz use gerrit)
2015/05/26 16:49:44
Array.prototype.length is not configurable, so thi
Toon Verwaest
2015/05/26 19:40:55
Shouldn't this be allowed to modify the value of t
jochen (gone - plz use gerrit)
2015/05/27 07:28:29
see v8natives.js
|
+ if (self->IsJSArray() && |
+ key->StrictEquals(Utils::ToLocal( |
+ isolate->factory()->NewStringFromStaticChars("length")))) { |
+ i::Handle<i::Object> args[] = {self, key_obj, value_obj}; |
+ i::Handle<i::Object> result; |
+ has_pending_exception = |
+ !CallV8HeapFunction(isolate, "$objectDefineArrayProperty", |
+ isolate->factory()->undefined_value(), |
+ arraysize(args), args).ToHandle(&result); |
+ RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
+ return Just(true); |
+ } |
+ |
+ i::LookupIterator it(self, key_obj, i::LookupIterator::OWN_SKIP_INTERCEPTOR); |
+ if (it.IsFound() && it.state() == i::LookupIterator::ACCESS_CHECK) { |
+ if (isolate->MayAccess(self)) return Just(false); |
noordhuis
2015/05/26 17:22:27
Should this be `if (!isolate->MayAccess(self)) ...
Toon Verwaest
2015/05/26 19:40:55
Yes. Seems like a missing test.
jochen (gone - plz use gerrit)
2015/05/27 07:28:30
done
|
+ it.Next(); |
+ } |
+ |
+ if (it.state() == i::LookupIterator::DATA || |
+ it.state() == i::LookupIterator::ACCESSOR) { |
+ if (it.property_details().attributes() & DONT_DELETE) return Just(false); |
+ |
+ if (it.state() == i::LookupIterator::ACCESSOR) { |
+ 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); |
+ } |
+ } |
+ |
+ |
+ has_pending_exception = i::Runtime::DefineObjectProperty( |
+ self, key_obj, value_obj, NONE).is_null(); |
+ RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
+ return Just(true); |
+} |
+ |
+ |
+Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, |
+ uint32_t index, |
+ v8::Local<Value> value) { |
+ PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", |
+ bool); |
+ auto self = Utils::OpenHandle(this); |
+ auto value_obj = Utils::OpenHandle(*value); |
+ if (!self->IsExtensible()) return Just(false); |
+ |
+ if (self->IsJSArray()) { |
+ size_t length = |
+ i::NumberToSize(isolate, i::Handle<i::JSArray>::cast(self)->length()); |
+ if (index >= length) { |
+ i::Handle<i::Object> args[] = { |
+ self, isolate->factory()->Uint32ToString(index), value_obj}; |
+ i::Handle<i::Object> result; |
+ has_pending_exception = |
+ !CallV8HeapFunction(isolate, "$objectDefineArrayProperty", |
+ isolate->factory()->undefined_value(), |
+ arraysize(args), args).ToHandle(&result); |
+ RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
+ return Just(true); |
+ } |
+ } |
+ |
+ if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) |
+ return Just(false); |
Toon Verwaest
2015/05/26 19:40:55
Add {} if on new line
jochen (gone - plz use gerrit)
2015/05/27 07:28:29
done
|
+ |
+ Maybe<PropertyAttributes> attributes = |
+ i::JSObject::GetElementAttributeWithReceiver(self, self, index, false); |
+ if (attributes.IsJust() && attributes.FromJust() != ABSENT) { |
+ if (attributes.FromJust() & DONT_DELETE) return Just(false); |
+ |
+ |
+ has_pending_exception = |
+ i::JSObject::SetOwnPropertyIgnoreAttributes( |
+ self, isolate->factory()->Uint32ToString(index), value_obj, NONE, |
Toon Verwaest
2015/05/26 19:40:55
You cannot use SetOwn... For elements at this mome
jochen (gone - plz use gerrit)
2015/05/27 07:28:29
this code path is covered by the test that sets ar
Toon Verwaest
2015/05/27 08:03:57
I can guarantee you that that code path doesn't wo
|
+ i::JSObject::DONT_FORCE_FIELD).is_null(); |
+ RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
+ return Just(true); |
+ } |
+ |
+ |
+ has_pending_exception = i::Runtime::DefineObjectProperty( |
+ self, isolate->factory()->Uint32ToString(index), |
+ value_obj, NONE).is_null(); |
+ RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
+ return Just(true); |
+} |
+ |
+ |
Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, |
v8::Local<Value> key, v8::Local<Value> value, |
v8::PropertyAttribute attribs) { |