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

Side by Side Diff: src/api.cc

Issue 1154233003: Introduce v8::Object::CreateDataProperty (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « include/v8.h ('k') | src/objects.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 3443 matching lines...) Expand 10 before | Expand all | Expand 10 after
3454 return Just(true); 3454 return Just(true);
3455 } 3455 }
3456 3456
3457 3457
3458 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { 3458 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) {
3459 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); 3459 auto context = ContextFromHeapObject(Utils::OpenHandle(this));
3460 return Set(context, index, value).FromMaybe(false); 3460 return Set(context, index, value).FromMaybe(false);
3461 } 3461 }
3462 3462
3463 3463
3464 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
3465 v8::Local<Name> key,
3466 v8::Local<Value> value) {
3467 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()",
3468 bool);
3469 auto self = Utils::OpenHandle(this);
3470 auto key_obj = Utils::OpenHandle(*key);
3471 auto value_obj = Utils::OpenHandle(*value);
3472 if (!self->IsExtensible()) return Just(false);
3473
3474 uint32_t index = 0;
3475 if (key_obj->AsArrayIndex(&index)) {
3476 return CreateDataProperty(context, index, value);
3477 }
3478
3479 // Special case for Array.length.
3480 if (self->IsJSArray() &&
3481 key->StrictEquals(Utils::ToLocal(
3482 isolate->factory()->NewStringFromStaticChars("length")))) {
Toon Verwaest 2015/05/27 09:50:06 isolate->factory()->length_string()
3483 // Length is not configurable, however, CreateDataProperty always attempts
3484 // to create a configurable property, so we just fail here.
3485 return Just(false);
3486 }
3487
3488 i::LookupIterator it(self, key_obj, i::LookupIterator::OWN_SKIP_INTERCEPTOR);
3489 if (it.IsFound() && it.state() == i::LookupIterator::ACCESS_CHECK) {
3490 if (!isolate->MayAccess(self)) return Just(false);
3491 it.Next();
3492 }
3493
3494 if (it.state() == i::LookupIterator::DATA ||
3495 it.state() == i::LookupIterator::ACCESSOR) {
3496 if (it.property_details().attributes() & DONT_DELETE) return Just(false);
Toon Verwaest 2015/05/27 09:50:06 !it.IsConfigurable()
3497
3498 if (it.state() == i::LookupIterator::ACCESSOR) {
3499 has_pending_exception = i::JSObject::SetOwnPropertyIgnoreAttributes(
3500 self, key_obj, value_obj, NONE,
3501 i::JSObject::DONT_FORCE_FIELD).is_null();
3502 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3503 return Just(true);
3504 }
3505 }
3506
3507 has_pending_exception = i::Runtime::DefineObjectProperty(
3508 self, key_obj, value_obj, NONE).is_null();
3509 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3510 return Just(true);
3511 }
3512
3513
3514 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
3515 uint32_t index,
3516 v8::Local<Value> value) {
3517 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()",
3518 bool);
3519 auto self = Utils::OpenHandle(this);
3520 auto value_obj = Utils::OpenHandle(*value);
3521 if (!self->IsExtensible()) return Just(false);
3522
3523 if (self->IsJSArray()) {
3524 size_t length =
3525 i::NumberToSize(isolate, i::Handle<i::JSArray>::cast(self)->length());
3526 if (index >= length) {
3527 i::Handle<i::Object> args[] = {
3528 self, isolate->factory()->Uint32ToString(index), value_obj};
3529 i::Handle<i::Object> result;
3530 has_pending_exception =
3531 !CallV8HeapFunction(isolate, "$objectDefineArrayProperty",
3532 isolate->factory()->undefined_value(),
3533 arraysize(args), args).ToHandle(&result);
3534 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3535 return Just(result->BooleanValue());
3536 }
3537 }
3538
3539 if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) {
Toon Verwaest 2015/05/27 09:50:06 According to https://etherpad.mozilla.org/html5-c
3540 return Just(false);
3541 }
3542
3543 Maybe<PropertyAttributes> attributes =
3544 i::JSReceiver::GetOwnElementAttribute(self, index);
3545 if (attributes.IsJust() && attributes.FromJust() & DONT_DELETE) {
3546 return Just(false);
3547 }
3548
3549 has_pending_exception = i::Runtime::DefineObjectProperty(
3550 self, isolate->factory()->Uint32ToString(index),
3551 value_obj, NONE).is_null();
3552 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3553 return Just(true);
3554 }
3555
3556
3464 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, 3557 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context,
3465 v8::Local<Value> key, v8::Local<Value> value, 3558 v8::Local<Value> key, v8::Local<Value> value,
3466 v8::PropertyAttribute attribs) { 3559 v8::PropertyAttribute attribs) {
3467 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); 3560 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool);
3468 auto self = Utils::OpenHandle(this); 3561 auto self = Utils::OpenHandle(this);
3469 auto key_obj = Utils::OpenHandle(*key); 3562 auto key_obj = Utils::OpenHandle(*key);
3470 auto value_obj = Utils::OpenHandle(*value); 3563 auto value_obj = Utils::OpenHandle(*value);
3471 has_pending_exception = i::Runtime::DefineObjectProperty( 3564 has_pending_exception = i::Runtime::DefineObjectProperty(
3472 self, 3565 self,
3473 key_obj, 3566 key_obj,
(...skipping 4635 matching lines...) Expand 10 before | Expand all | Expand 10 after
8109 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 8202 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
8110 Address callback_address = 8203 Address callback_address =
8111 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8204 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8112 VMState<EXTERNAL> state(isolate); 8205 VMState<EXTERNAL> state(isolate);
8113 ExternalCallbackScope call_scope(isolate, callback_address); 8206 ExternalCallbackScope call_scope(isolate, callback_address);
8114 callback(info); 8207 callback(info);
8115 } 8208 }
8116 8209
8117 8210
8118 } } // namespace v8::internal 8211 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698