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 3654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3665 | 3665 |
3666 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, | 3666 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, |
3667 v8::Local<Name> key, | 3667 v8::Local<Name> key, |
3668 v8::Local<Value> value, | 3668 v8::Local<Value> value, |
3669 v8::PropertyAttribute attributes) { | 3669 v8::PropertyAttribute attributes) { |
3670 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Object, DefineOwnProperty, bool); | 3670 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Object, DefineOwnProperty, bool); |
3671 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); | 3671 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); |
3672 i::Handle<i::Name> key_obj = Utils::OpenHandle(*key); | 3672 i::Handle<i::Name> key_obj = Utils::OpenHandle(*key); |
3673 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); | 3673 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
3674 | 3674 |
3675 if (self->IsAccessCheckNeeded() && | |
3676 !isolate->MayAccess(handle(isolate->context()), | |
3677 i::Handle<i::JSObject>::cast(self))) { | |
3678 isolate->ReportFailedAccessCheck(i::Handle<i::JSObject>::cast(self)); | |
3679 return Nothing<bool>(); | |
3680 } | |
3681 | |
3682 i::PropertyDescriptor desc; | 3675 i::PropertyDescriptor desc; |
3683 desc.set_writable(!(attributes & v8::ReadOnly)); | 3676 desc.set_writable(!(attributes & v8::ReadOnly)); |
3684 desc.set_enumerable(!(attributes & v8::DontEnum)); | 3677 desc.set_enumerable(!(attributes & v8::DontEnum)); |
3685 desc.set_configurable(!(attributes & v8::DontDelete)); | 3678 desc.set_configurable(!(attributes & v8::DontDelete)); |
3686 desc.set_value(value_obj); | 3679 desc.set_value(value_obj); |
3687 Maybe<bool> success = i::JSReceiver::DefineOwnProperty( | 3680 Maybe<bool> success = i::JSReceiver::DefineOwnProperty( |
3688 isolate, self, key_obj, &desc, i::Object::DONT_THROW); | 3681 isolate, self, key_obj, &desc, i::Object::DONT_THROW); |
3689 // Even though we said DONT_THROW, there might be accessors that do throw. | 3682 // Even though we said DONT_THROW, there might be accessors that do throw. |
3690 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3683 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
3691 return success; | 3684 return success; |
3692 } | 3685 } |
3693 | 3686 |
| 3687 Maybe<bool> v8::Object::DefineProperty(v8::Local<v8::Context> context, |
| 3688 v8::Local<Name> key, |
| 3689 const PropertyDescriptor& descriptor) { |
| 3690 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Object, DefineProperty, bool); |
| 3691 auto self = Utils::OpenHandle(this); |
| 3692 auto key_obj = Utils::OpenHandle(*key); |
| 3693 |
| 3694 i::PropertyDescriptor desc; |
| 3695 if (descriptor.has_value()) { |
| 3696 if (descriptor.value().IsEmpty()) { |
| 3697 desc.set_value(isolate->factory()->undefined_value()); |
| 3698 } else { |
| 3699 desc.set_value(Utils::OpenHandle(*descriptor.value())); |
| 3700 } |
| 3701 } |
| 3702 if (descriptor.has_get()) { |
| 3703 if (descriptor.get().IsEmpty()) { |
| 3704 desc.set_get(isolate->factory()->undefined_value()); |
| 3705 } else { |
| 3706 desc.set_get(Utils::OpenHandle(*descriptor.get())); |
| 3707 } |
| 3708 } |
| 3709 if (descriptor.has_set()) { |
| 3710 if (descriptor.set().IsEmpty()) { |
| 3711 desc.set_set(isolate->factory()->undefined_value()); |
| 3712 } else { |
| 3713 desc.set_set(Utils::OpenHandle(*descriptor.set())); |
| 3714 } |
| 3715 } |
| 3716 if (descriptor.has_enumerable()) { |
| 3717 desc.set_enumerable(descriptor.enumerable()); |
| 3718 } |
| 3719 if (descriptor.has_configurable()) { |
| 3720 desc.set_configurable(descriptor.configurable()); |
| 3721 } |
| 3722 if (descriptor.has_writable()) { |
| 3723 desc.set_writable(descriptor.writable()); |
| 3724 } |
| 3725 |
| 3726 auto success = i::JSReceiver::DefineOwnProperty(isolate, self, key_obj, &desc, |
| 3727 i::Object::DONT_THROW); |
| 3728 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 3729 return success; |
| 3730 } |
3694 | 3731 |
3695 MUST_USE_RESULT | 3732 MUST_USE_RESULT |
3696 static i::MaybeHandle<i::Object> DefineObjectProperty( | 3733 static i::MaybeHandle<i::Object> DefineObjectProperty( |
3697 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, | 3734 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, |
3698 i::Handle<i::Object> value, i::PropertyAttributes attrs) { | 3735 i::Handle<i::Object> value, i::PropertyAttributes attrs) { |
3699 i::Isolate* isolate = js_object->GetIsolate(); | 3736 i::Isolate* isolate = js_object->GetIsolate(); |
3700 bool success = false; | 3737 bool success = false; |
3701 i::LookupIterator it = i::LookupIterator::PropertyOrElement( | 3738 i::LookupIterator it = i::LookupIterator::PropertyOrElement( |
3702 isolate, js_object, key, &success, i::LookupIterator::OWN); | 3739 isolate, js_object, key, &success, i::LookupIterator::OWN); |
3703 if (!success) return i::MaybeHandle<i::Object>(); | 3740 if (!success) return i::MaybeHandle<i::Object>(); |
(...skipping 5313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9017 Address callback_address = | 9054 Address callback_address = |
9018 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9055 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9019 VMState<EXTERNAL> state(isolate); | 9056 VMState<EXTERNAL> state(isolate); |
9020 ExternalCallbackScope call_scope(isolate, callback_address); | 9057 ExternalCallbackScope call_scope(isolate, callback_address); |
9021 callback(info); | 9058 callback(info); |
9022 } | 9059 } |
9023 | 9060 |
9024 | 9061 |
9025 } // namespace internal | 9062 } // namespace internal |
9026 } // namespace v8 | 9063 } // namespace v8 |
OLD | NEW |