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 3517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3528 } | 3528 } |
3529 | 3529 |
3530 i::LookupIterator it(self, key_obj, i::LookupIterator::OWN_SKIP_INTERCEPTOR); | 3530 i::LookupIterator it(self, key_obj, i::LookupIterator::OWN_SKIP_INTERCEPTOR); |
3531 if (it.IsFound() && it.state() == i::LookupIterator::ACCESS_CHECK) { | 3531 if (it.IsFound() && it.state() == i::LookupIterator::ACCESS_CHECK) { |
3532 DCHECK(isolate->MayAccess(self)); | 3532 DCHECK(isolate->MayAccess(self)); |
3533 it.Next(); | 3533 it.Next(); |
3534 } | 3534 } |
3535 | 3535 |
3536 if (it.IsFound() && !it.IsConfigurable()) return Just(false); | 3536 if (it.IsFound() && !it.IsConfigurable()) return Just(false); |
3537 | 3537 |
3538 has_pending_exception = | 3538 has_pending_exception = i::JSObject::SetOwnPropertyIgnoreAttributes( |
3539 i::Runtime::DefineObjectProperty(self, key_obj, value_obj, NONE, | 3539 self, key_obj, value_obj, NONE, |
3540 i::JSObject::DONT_FORCE_FIELD).is_null(); | 3540 i::JSObject::DONT_FORCE_FIELD).is_null(); |
3541 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3541 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3542 return Just(true); | 3542 return Just(true); |
3543 } | 3543 } |
3544 | 3544 |
3545 | 3545 |
3546 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, | 3546 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, |
3547 uint32_t index, | 3547 uint32_t index, |
3548 v8::Local<Value> value) { | 3548 v8::Local<Value> value) { |
3549 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", | 3549 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", |
3550 bool); | 3550 bool); |
(...skipping 16 matching lines...) Expand all Loading... |
3567 value, v8::None); | 3567 value, v8::None); |
3568 } | 3568 } |
3569 } | 3569 } |
3570 | 3570 |
3571 Maybe<PropertyAttributes> attributes = | 3571 Maybe<PropertyAttributes> attributes = |
3572 i::JSReceiver::GetOwnElementAttributes(self, index); | 3572 i::JSReceiver::GetOwnElementAttributes(self, index); |
3573 if (attributes.IsJust() && attributes.FromJust() & DONT_DELETE) { | 3573 if (attributes.IsJust() && attributes.FromJust() & DONT_DELETE) { |
3574 return Just(false); | 3574 return Just(false); |
3575 } | 3575 } |
3576 | 3576 |
3577 has_pending_exception = | 3577 has_pending_exception = i::JSObject::SetOwnElementIgnoreAttributes( |
3578 i::Runtime::DefineObjectProperty( | 3578 self, index, value_obj, NONE, |
3579 self, isolate->factory()->Uint32ToString(index), value_obj, NONE, | 3579 i::JSObject::DONT_FORCE_FIELD).is_null(); |
3580 i::JSObject::DONT_FORCE_FIELD).is_null(); | |
3581 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3580 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3582 return Just(true); | 3581 return Just(true); |
3583 } | 3582 } |
3584 | 3583 |
3585 | 3584 |
3586 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, | 3585 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, |
3587 v8::Local<Name> key, | 3586 v8::Local<Name> key, |
3588 v8::Local<Value> value, | 3587 v8::Local<Value> value, |
3589 v8::PropertyAttribute attributes) { | 3588 v8::PropertyAttribute attributes) { |
3590 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DefineOwnProperty()", | 3589 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DefineOwnProperty()", |
(...skipping 17 matching lines...) Expand all Loading... |
3608 i::Handle<i::Object> result; | 3607 i::Handle<i::Object> result; |
3609 has_pending_exception = | 3608 has_pending_exception = |
3610 !CallV8HeapFunction(isolate, "$objectDefineOwnProperty", | 3609 !CallV8HeapFunction(isolate, "$objectDefineOwnProperty", |
3611 isolate->factory()->undefined_value(), | 3610 isolate->factory()->undefined_value(), |
3612 arraysize(args), args).ToHandle(&result); | 3611 arraysize(args), args).ToHandle(&result); |
3613 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3612 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3614 return Just(result->BooleanValue()); | 3613 return Just(result->BooleanValue()); |
3615 } | 3614 } |
3616 | 3615 |
3617 | 3616 |
| 3617 MUST_USE_RESULT |
| 3618 static i::MaybeHandle<i::Object> DefineObjectProperty( |
| 3619 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, |
| 3620 i::Handle<i::Object> value, PropertyAttributes attrs) { |
| 3621 i::Isolate* isolate = js_object->GetIsolate(); |
| 3622 // Check if the given key is an array index. |
| 3623 uint32_t index = 0; |
| 3624 if (key->ToArrayIndex(&index)) { |
| 3625 return i::JSObject::SetOwnElementIgnoreAttributes(js_object, index, value, |
| 3626 attrs); |
| 3627 } |
| 3628 |
| 3629 i::Handle<i::Name> name; |
| 3630 if (key->IsName()) { |
| 3631 name = i::Handle<i::Name>::cast(key); |
| 3632 } else { |
| 3633 // Call-back into JavaScript to convert the key to a string. |
| 3634 i::Handle<i::Object> converted; |
| 3635 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, converted, |
| 3636 i::Execution::ToString(isolate, key), |
| 3637 i::MaybeHandle<i::Object>()); |
| 3638 name = i::Handle<i::String>::cast(converted); |
| 3639 } |
| 3640 |
| 3641 return i::JSObject::DefinePropertyOrElement(js_object, name, value, attrs); |
| 3642 } |
| 3643 |
| 3644 |
3618 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, | 3645 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, |
3619 v8::Local<Value> key, v8::Local<Value> value, | 3646 v8::Local<Value> key, v8::Local<Value> value, |
3620 v8::PropertyAttribute attribs) { | 3647 v8::PropertyAttribute attribs) { |
3621 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); | 3648 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); |
3622 auto self = Utils::OpenHandle(this); | 3649 auto self = Utils::OpenHandle(this); |
3623 auto key_obj = Utils::OpenHandle(*key); | 3650 auto key_obj = Utils::OpenHandle(*key); |
3624 auto value_obj = Utils::OpenHandle(*value); | 3651 auto value_obj = Utils::OpenHandle(*value); |
3625 has_pending_exception = i::Runtime::DefineObjectProperty( | 3652 has_pending_exception = |
3626 self, | 3653 DefineObjectProperty(self, key_obj, value_obj, |
3627 key_obj, | 3654 static_cast<PropertyAttributes>(attribs)).is_null(); |
3628 value_obj, | |
3629 static_cast<PropertyAttributes>(attribs)).is_null(); | |
3630 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3655 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3631 return Just(true); | 3656 return Just(true); |
3632 } | 3657 } |
3633 | 3658 |
3634 | 3659 |
3635 bool v8::Object::ForceSet(v8::Handle<Value> key, v8::Handle<Value> value, | 3660 bool v8::Object::ForceSet(v8::Handle<Value> key, v8::Handle<Value> value, |
3636 v8::PropertyAttribute attribs) { | 3661 v8::PropertyAttribute attribs) { |
3637 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 3662 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
3638 PREPARE_FOR_EXECUTION_GENERIC(isolate, Local<Context>(), | 3663 PREPARE_FOR_EXECUTION_GENERIC(isolate, Local<Context>(), |
3639 "v8::Object::ForceSet", false, i::HandleScope, | 3664 "v8::Object::ForceSet", false, i::HandleScope, |
3640 false); | 3665 false); |
3641 i::Handle<i::JSObject> self = Utils::OpenHandle(this); | 3666 i::Handle<i::JSObject> self = Utils::OpenHandle(this); |
3642 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); | 3667 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); |
3643 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); | 3668 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
3644 has_pending_exception = | 3669 has_pending_exception = |
3645 i::Runtime::DefineObjectProperty(self, key_obj, value_obj, | 3670 DefineObjectProperty(self, key_obj, value_obj, |
3646 static_cast<PropertyAttributes>(attribs)) | 3671 static_cast<PropertyAttributes>(attribs)).is_null(); |
3647 .is_null(); | |
3648 EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, false); | 3672 EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, false); |
3649 return true; | 3673 return true; |
3650 } | 3674 } |
3651 | 3675 |
3652 | 3676 |
3653 namespace { | 3677 namespace { |
3654 | 3678 |
3655 i::MaybeHandle<i::Object> DeleteObjectProperty( | 3679 i::MaybeHandle<i::Object> DeleteObjectProperty( |
3656 i::Isolate* isolate, i::Handle<i::JSReceiver> receiver, | 3680 i::Isolate* isolate, i::Handle<i::JSReceiver> receiver, |
3657 i::Handle<i::Object> key, i::LanguageMode language_mode) { | 3681 i::Handle<i::Object> key, i::LanguageMode language_mode) { |
(...skipping 4761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8419 Address callback_address = | 8443 Address callback_address = |
8420 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8444 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8421 VMState<EXTERNAL> state(isolate); | 8445 VMState<EXTERNAL> state(isolate); |
8422 ExternalCallbackScope call_scope(isolate, callback_address); | 8446 ExternalCallbackScope call_scope(isolate, callback_address); |
8423 callback(info); | 8447 callback(info); |
8424 } | 8448 } |
8425 | 8449 |
8426 | 8450 |
8427 } // namespace internal | 8451 } // namespace internal |
8428 } // namespace v8 | 8452 } // namespace v8 |
OLD | NEW |