Chromium Code Reviews| 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 3753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3764 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); | 3764 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
| 3765 | 3765 |
| 3766 i::LookupIterator it(isolate, self, index, self, i::LookupIterator::OWN); | 3766 i::LookupIterator it(isolate, self, index, self, i::LookupIterator::OWN); |
| 3767 Maybe<bool> result = | 3767 Maybe<bool> result = |
| 3768 i::JSReceiver::CreateDataProperty(&it, value_obj, i::Object::DONT_THROW); | 3768 i::JSReceiver::CreateDataProperty(&it, value_obj, i::Object::DONT_THROW); |
| 3769 has_pending_exception = result.IsNothing(); | 3769 has_pending_exception = result.IsNothing(); |
| 3770 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3770 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 3771 return result; | 3771 return result; |
| 3772 } | 3772 } |
| 3773 | 3773 |
| 3774 struct v8::PropertyDescriptor::PrivateData { | |
| 3775 PrivateData() : desc() {} | |
| 3776 i::PropertyDescriptor desc; | |
| 3777 }; | |
| 3778 | |
| 3779 v8::PropertyDescriptor::PropertyDescriptor() : private_(new PrivateData()) {} | |
| 3780 | |
| 3781 // DataDescriptor | |
| 3782 v8::PropertyDescriptor::PropertyDescriptor( | |
| 3783 v8::Local<v8::Value> value, v8::PropertyDescriptor::State writable) | |
| 3784 : private_(new PrivateData()) { | |
| 3785 private_->desc.set_value(Utils::OpenHandle(*value, true)); | |
| 3786 if (writable == v8::PropertyDescriptor::State::kTrue) { | |
| 3787 private_->desc.set_writable(true); | |
| 3788 } else if (writable == v8::PropertyDescriptor::State::kFalse) { | |
| 3789 private_->desc.set_writable(false); | |
| 3790 } | |
| 3791 } | |
| 3792 | |
| 3793 // AccessorDescriptor | |
| 3794 v8::PropertyDescriptor::PropertyDescriptor(v8::Local<v8::Value> get, | |
| 3795 v8::Local<v8::Value> set) | |
| 3796 : private_(new PrivateData()) { | |
| 3797 DCHECK(get.IsEmpty() || get->IsUndefined() || get->IsFunction()); | |
| 3798 DCHECK(set.IsEmpty() || set->IsUndefined() || set->IsFunction()); | |
| 3799 private_->desc.set_get(Utils::OpenHandle(*get, true)); | |
| 3800 private_->desc.set_set(Utils::OpenHandle(*set, true)); | |
| 3801 } | |
| 3802 | |
| 3803 v8::PropertyDescriptor::~PropertyDescriptor() { delete private_; } | |
| 3804 | |
| 3805 v8::Local<Value> v8::PropertyDescriptor::value() const { | |
| 3806 return Utils::ToLocal(private_->desc.value()); | |
| 3807 } | |
| 3808 | |
| 3809 v8::Local<Value> v8::PropertyDescriptor::get() const { | |
| 3810 return Utils::ToLocal(private_->desc.get()); | |
| 3811 } | |
| 3812 | |
| 3813 v8::Local<Value> v8::PropertyDescriptor::set() const { | |
| 3814 return Utils::ToLocal(private_->desc.set()); | |
| 3815 } | |
| 3816 | |
| 3817 bool v8::PropertyDescriptor::has_value() const { | |
| 3818 return private_->desc.has_value(); | |
| 3819 } | |
| 3820 bool v8::PropertyDescriptor::has_get() const { | |
| 3821 return private_->desc.has_get(); | |
| 3822 } | |
| 3823 bool v8::PropertyDescriptor::has_set() const { | |
| 3824 return private_->desc.has_set(); | |
| 3825 } | |
| 3826 | |
| 3827 PropertyDescriptor::State v8::PropertyDescriptor::writable() const { | |
| 3828 if (!private_->desc.has_writable()) { | |
| 3829 return PropertyDescriptor::State::kNotSet; | |
| 3830 } | |
| 3831 if (private_->desc.writable()) { | |
| 3832 return PropertyDescriptor::State::kTrue; | |
| 3833 } | |
| 3834 return PropertyDescriptor::State::kFalse; | |
| 3835 } | |
| 3836 | |
| 3837 void v8::PropertyDescriptor::set_enumerable(bool enumerable) { | |
| 3838 private_->desc.set_enumerable(enumerable); | |
| 3839 } | |
| 3840 PropertyDescriptor::State v8::PropertyDescriptor::enumerable() const { | |
| 3841 if (!private_->desc.has_enumerable()) { | |
| 3842 return PropertyDescriptor::State::kNotSet; | |
| 3843 } | |
| 3844 if (private_->desc.enumerable()) { | |
| 3845 return PropertyDescriptor::State::kTrue; | |
| 3846 } | |
| 3847 return PropertyDescriptor::State::kFalse; | |
| 3848 } | |
| 3849 | |
| 3850 void v8::PropertyDescriptor::set_configurable(bool configurable) { | |
| 3851 private_->desc.set_configurable(configurable); | |
| 3852 } | |
| 3853 PropertyDescriptor::State v8::PropertyDescriptor::configurable() const { | |
| 3854 if (!private_->desc.has_configurable()) { | |
| 3855 return PropertyDescriptor::State::kNotSet; | |
| 3856 } | |
| 3857 if (private_->desc.configurable()) { | |
| 3858 return PropertyDescriptor::State::kTrue; | |
| 3859 } | |
| 3860 return PropertyDescriptor::State::kFalse; | |
| 3861 } | |
| 3774 | 3862 |
| 3775 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, | 3863 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, |
| 3776 v8::Local<Name> key, | 3864 v8::Local<Name> key, |
| 3777 v8::Local<Value> value, | 3865 v8::Local<Value> value, |
| 3778 v8::PropertyAttribute attributes) { | 3866 v8::PropertyAttribute attributes) { |
| 3779 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Object, DefineOwnProperty, bool); | 3867 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Object, DefineOwnProperty, bool); |
| 3780 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); | 3868 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); |
| 3781 i::Handle<i::Name> key_obj = Utils::OpenHandle(*key); | 3869 i::Handle<i::Name> key_obj = Utils::OpenHandle(*key); |
| 3782 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); | 3870 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); |
| 3783 | 3871 |
| 3784 if (self->IsAccessCheckNeeded() && | |
| 3785 !isolate->MayAccess(handle(isolate->context()), | |
| 3786 i::Handle<i::JSObject>::cast(self))) { | |
| 3787 isolate->ReportFailedAccessCheck(i::Handle<i::JSObject>::cast(self)); | |
| 3788 return Nothing<bool>(); | |
| 3789 } | |
| 3790 | |
| 3791 i::PropertyDescriptor desc; | 3872 i::PropertyDescriptor desc; |
| 3792 desc.set_writable(!(attributes & v8::ReadOnly)); | 3873 desc.set_writable(!(attributes & v8::ReadOnly)); |
| 3793 desc.set_enumerable(!(attributes & v8::DontEnum)); | 3874 desc.set_enumerable(!(attributes & v8::DontEnum)); |
| 3794 desc.set_configurable(!(attributes & v8::DontDelete)); | 3875 desc.set_configurable(!(attributes & v8::DontDelete)); |
| 3795 desc.set_value(value_obj); | 3876 desc.set_value(value_obj); |
| 3796 Maybe<bool> success = i::JSReceiver::DefineOwnProperty( | 3877 Maybe<bool> success = i::JSReceiver::DefineOwnProperty( |
| 3797 isolate, self, key_obj, &desc, i::Object::DONT_THROW); | 3878 isolate, self, key_obj, &desc, i::Object::DONT_THROW); |
| 3798 // Even though we said DONT_THROW, there might be accessors that do throw. | 3879 // Even though we said DONT_THROW, there might be accessors that do throw. |
| 3799 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | 3880 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 3800 return success; | 3881 return success; |
| 3801 } | 3882 } |
| 3802 | 3883 |
| 3884 Maybe<bool> v8::Object::DefineProperty(v8::Local<v8::Context> context, | |
| 3885 v8::Local<Name> key, | |
| 3886 const PropertyDescriptor& descriptor) { | |
| 3887 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Object, DefineProperty, bool); | |
| 3888 auto self = Utils::OpenHandle(this); | |
|
Jakob Kummerow
2016/08/29 12:32:24
nit: no "auto" please
Franzi
2016/08/31 09:44:13
Done.
| |
| 3889 auto key_obj = Utils::OpenHandle(*key); | |
| 3890 | |
| 3891 i::PropertyDescriptor desc; | |
| 3892 desc.set_value(Utils::OpenHandle(*descriptor.value(), true)); | |
| 3893 desc.set_get(Utils::OpenHandle(*descriptor.get(), true)); | |
| 3894 desc.set_set(Utils::OpenHandle(*descriptor.set(), true)); | |
| 3895 if (descriptor.enumerable() == PropertyDescriptor::State::kTrue) { | |
| 3896 desc.set_enumerable(true); | |
| 3897 } else if (descriptor.enumerable() == PropertyDescriptor::State::kFalse) { | |
| 3898 desc.set_enumerable(false); | |
| 3899 } | |
| 3900 if (descriptor.configurable() == PropertyDescriptor::State::kTrue) { | |
| 3901 desc.set_configurable(true); | |
| 3902 } else if (descriptor.configurable() == PropertyDescriptor::State::kFalse) { | |
| 3903 desc.set_configurable(false); | |
| 3904 } | |
| 3905 if (descriptor.writable() == PropertyDescriptor::State::kTrue) { | |
| 3906 desc.set_writable(true); | |
| 3907 } else if (descriptor.writable() == PropertyDescriptor::State::kFalse) { | |
| 3908 desc.set_writable(false); | |
| 3909 } | |
| 3910 | |
| 3911 auto success = i::JSReceiver::DefineOwnProperty(isolate, self, key_obj, &desc, | |
| 3912 i::Object::DONT_THROW); | |
| 3913 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
| 3914 return success; | |
| 3915 } | |
| 3803 | 3916 |
| 3804 MUST_USE_RESULT | 3917 MUST_USE_RESULT |
| 3805 static i::MaybeHandle<i::Object> DefineObjectProperty( | 3918 static i::MaybeHandle<i::Object> DefineObjectProperty( |
| 3806 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, | 3919 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, |
| 3807 i::Handle<i::Object> value, i::PropertyAttributes attrs) { | 3920 i::Handle<i::Object> value, i::PropertyAttributes attrs) { |
| 3808 i::Isolate* isolate = js_object->GetIsolate(); | 3921 i::Isolate* isolate = js_object->GetIsolate(); |
| 3809 bool success = false; | 3922 bool success = false; |
| 3810 i::LookupIterator it = i::LookupIterator::PropertyOrElement( | 3923 i::LookupIterator it = i::LookupIterator::PropertyOrElement( |
| 3811 isolate, js_object, key, &success, i::LookupIterator::OWN); | 3924 isolate, js_object, key, &success, i::LookupIterator::OWN); |
| 3812 if (!success) return i::MaybeHandle<i::Object>(); | 3925 if (!success) return i::MaybeHandle<i::Object>(); |
| (...skipping 5284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9097 Address callback_address = | 9210 Address callback_address = |
| 9098 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9211 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 9099 VMState<EXTERNAL> state(isolate); | 9212 VMState<EXTERNAL> state(isolate); |
| 9100 ExternalCallbackScope call_scope(isolate, callback_address); | 9213 ExternalCallbackScope call_scope(isolate, callback_address); |
| 9101 callback(info); | 9214 callback(info); |
| 9102 } | 9215 } |
| 9103 | 9216 |
| 9104 | 9217 |
| 9105 } // namespace internal | 9218 } // namespace internal |
| 9106 } // namespace v8 | 9219 } // namespace v8 |
| OLD | NEW |