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); | |
Jakob Kummerow
2016/08/26 13:28:30
nit: please don't use auto, make the type explicit
| |
3692 auto key_obj = Utils::OpenHandle(*key); | |
3693 | |
3694 i::PropertyDescriptor desc; | |
3695 if (descriptor.has_value()) { | |
3696 if (descriptor.value().IsEmpty()) { | |
3697 return Nothing<bool>(); | |
3698 } | |
3699 desc.set_value(Utils::OpenHandle(*descriptor.value())); | |
3700 } | |
3701 if (descriptor.has_get()) { | |
3702 if (descriptor.get().IsEmpty()) { | |
3703 desc.set_get(isolate->factory()->undefined_value()); | |
3704 } else { | |
3705 desc.set_get(Utils::OpenHandle(*descriptor.get())); | |
3706 } | |
3707 } | |
3708 if (descriptor.has_set()) { | |
3709 if (descriptor.set().IsEmpty()) { | |
3710 desc.set_set(isolate->factory()->undefined_value()); | |
3711 } else { | |
3712 desc.set_set(Utils::OpenHandle(*descriptor.set())); | |
3713 } | |
3714 } | |
3715 if (descriptor.has_enumerable()) { | |
3716 desc.set_enumerable(descriptor.enumerable()); | |
3717 } | |
3718 if (descriptor.has_configurable()) { | |
3719 desc.set_configurable(descriptor.configurable()); | |
3720 } | |
3721 if (descriptor.has_writable()) { | |
3722 desc.set_writable(descriptor.writable()); | |
3723 } | |
3724 | |
3725 auto success = i::JSReceiver::DefineOwnProperty(isolate, self, key_obj, &desc, | |
3726 i::Object::DONT_THROW); | |
3727 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
3728 return success; | |
3729 } | |
3694 | 3730 |
3695 MUST_USE_RESULT | 3731 MUST_USE_RESULT |
3696 static i::MaybeHandle<i::Object> DefineObjectProperty( | 3732 static i::MaybeHandle<i::Object> DefineObjectProperty( |
3697 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, | 3733 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, |
3698 i::Handle<i::Object> value, i::PropertyAttributes attrs) { | 3734 i::Handle<i::Object> value, i::PropertyAttributes attrs) { |
3699 i::Isolate* isolate = js_object->GetIsolate(); | 3735 i::Isolate* isolate = js_object->GetIsolate(); |
3700 bool success = false; | 3736 bool success = false; |
3701 i::LookupIterator it = i::LookupIterator::PropertyOrElement( | 3737 i::LookupIterator it = i::LookupIterator::PropertyOrElement( |
3702 isolate, js_object, key, &success, i::LookupIterator::OWN); | 3738 isolate, js_object, key, &success, i::LookupIterator::OWN); |
3703 if (!success) return i::MaybeHandle<i::Object>(); | 3739 if (!success) return i::MaybeHandle<i::Object>(); |
(...skipping 5284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8988 Address callback_address = | 9024 Address callback_address = |
8989 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9025 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8990 VMState<EXTERNAL> state(isolate); | 9026 VMState<EXTERNAL> state(isolate); |
8991 ExternalCallbackScope call_scope(isolate, callback_address); | 9027 ExternalCallbackScope call_scope(isolate, callback_address); |
8992 callback(info); | 9028 callback(info); |
8993 } | 9029 } |
8994 | 9030 |
8995 | 9031 |
8996 } // namespace internal | 9032 } // namespace internal |
8997 } // namespace v8 | 9033 } // namespace v8 |
OLD | NEW |