OLD | NEW |
---|---|
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 3485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3496 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 3496 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
3497 return Set(context, index, value).FromMaybe(false); | 3497 return Set(context, index, value).FromMaybe(false); |
3498 } | 3498 } |
3499 | 3499 |
3500 | 3500 |
3501 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, | 3501 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, |
3502 v8::Local<Name> key, | 3502 v8::Local<Name> key, |
3503 v8::Local<Value> value) { | 3503 v8::Local<Value> value) { |
3504 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", | 3504 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", |
3505 bool); | 3505 bool); |
3506 auto self = Utils::OpenHandle(this); | 3506 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
Jakob Kummerow
2015/06/17 10:53:30
Yay! :-)
| |
3507 auto key_obj = Utils::OpenHandle(*key); | 3507 i::Handle<i::Name> key_obj = Utils::OpenHandle(*key); |
3508 auto value_obj = Utils::OpenHandle(*value); | 3508 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
3509 | 3509 |
3510 if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) { | 3510 i::LookupIterator it = i::LookupIterator::PropertyOrElement( |
3511 isolate->ReportFailedAccessCheck(self); | 3511 isolate, self, key_obj, i::LookupIterator::OWN); |
3512 return Nothing<bool>(); | 3512 Maybe<bool> result = i::JSObject::CreateDataProperty(&it, value_obj); |
3513 } | 3513 has_pending_exception = result.IsNothing(); |
3514 | |
3515 if (!self->IsExtensible()) return Just(false); | |
3516 | |
3517 uint32_t index = 0; | |
3518 if (key_obj->AsArrayIndex(&index)) { | |
3519 return CreateDataProperty(context, index, value); | |
3520 } | |
3521 | |
3522 // Special case for Array.length. | |
3523 if (self->IsJSArray() && | |
3524 key->StrictEquals(Utils::ToLocal(isolate->factory()->length_string()))) { | |
3525 // Length is not configurable, however, CreateDataProperty always attempts | |
3526 // to create a configurable property, so we just fail here. | |
3527 return Just(false); | |
3528 } | |
3529 | |
3530 i::LookupIterator it(self, key_obj, i::LookupIterator::OWN_SKIP_INTERCEPTOR); | |
3531 if (it.IsFound() && it.state() == i::LookupIterator::ACCESS_CHECK) { | |
3532 DCHECK(isolate->MayAccess(self)); | |
3533 it.Next(); | |
3534 } | |
3535 | |
3536 if (it.IsFound() && !it.IsConfigurable()) return Just(false); | |
3537 | |
3538 has_pending_exception = i::JSObject::SetOwnPropertyIgnoreAttributes( | |
3539 self, key_obj, value_obj, NONE, | |
3540 i::JSObject::DONT_FORCE_FIELD).is_null(); | |
3541 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3514 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3542 return Just(true); | 3515 return result; |
3543 } | 3516 } |
3544 | 3517 |
3545 | 3518 |
3546 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, | 3519 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, |
3547 uint32_t index, | 3520 uint32_t index, |
3548 v8::Local<Value> value) { | 3521 v8::Local<Value> value) { |
3549 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", | 3522 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", |
3550 bool); | 3523 bool); |
3551 auto self = Utils::OpenHandle(this); | 3524 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
3552 auto value_obj = Utils::OpenHandle(*value); | 3525 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
3553 | 3526 |
3554 if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) { | 3527 i::LookupIterator it(isolate, self, index, i::LookupIterator::OWN); |
3555 isolate->ReportFailedAccessCheck(self); | 3528 Maybe<bool> result = i::JSObject::CreateDataProperty(&it, value_obj); |
3556 return Nothing<bool>(); | 3529 has_pending_exception = result.IsNothing(); |
3557 } | |
3558 | |
3559 if (!self->IsExtensible()) return Just(false); | |
3560 | |
3561 if (self->IsJSArray()) { | |
3562 size_t length = | |
3563 i::NumberToSize(isolate, i::Handle<i::JSArray>::cast(self)->length()); | |
3564 if (index >= length) { | |
3565 return DefineOwnProperty( | |
3566 context, Utils::ToLocal(isolate->factory()->Uint32ToString(index)), | |
3567 value, v8::None); | |
3568 } | |
3569 } | |
3570 | |
3571 Maybe<PropertyAttributes> attributes = | |
3572 i::JSReceiver::GetOwnElementAttributes(self, index); | |
3573 if (attributes.IsJust() && attributes.FromJust() & DONT_DELETE) { | |
3574 return Just(false); | |
3575 } | |
3576 | |
3577 has_pending_exception = i::JSObject::SetOwnElementIgnoreAttributes( | |
3578 self, index, value_obj, NONE, | |
3579 i::JSObject::DONT_FORCE_FIELD).is_null(); | |
3580 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3530 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3581 return Just(true); | 3531 return result; |
3582 } | 3532 } |
3583 | 3533 |
3584 | 3534 |
3585 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, | 3535 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, |
3586 v8::Local<Name> key, | 3536 v8::Local<Name> key, |
3587 v8::Local<Value> value, | 3537 v8::Local<Value> value, |
3588 v8::PropertyAttribute attributes) { | 3538 v8::PropertyAttribute attributes) { |
3589 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DefineOwnProperty()", | 3539 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DefineOwnProperty()", |
3590 bool); | 3540 bool); |
3591 auto self = Utils::OpenHandle(this); | 3541 auto self = Utils::OpenHandle(this); |
(...skipping 4854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8446 Address callback_address = | 8396 Address callback_address = |
8447 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8397 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8448 VMState<EXTERNAL> state(isolate); | 8398 VMState<EXTERNAL> state(isolate); |
8449 ExternalCallbackScope call_scope(isolate, callback_address); | 8399 ExternalCallbackScope call_scope(isolate, callback_address); |
8450 callback(info); | 8400 callback(info); |
8451 } | 8401 } |
8452 | 8402 |
8453 | 8403 |
8454 } // namespace internal | 8404 } // namespace internal |
8455 } // namespace v8 | 8405 } // namespace v8 |
OLD | NEW |