Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: src/api.cc

Issue 2244123005: [api] Add PropertyDescriptor and DefineProperty(). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add test that shows need for has_attribute() functions Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« include/v8.h ('K') | « include/v8.h ('k') | src/counters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3673 matching lines...) Expand 10 before | Expand all | Expand 10 after
3684 desc.set_enumerable(!(attributes & v8::DontEnum)); 3684 desc.set_enumerable(!(attributes & v8::DontEnum));
3685 desc.set_configurable(!(attributes & v8::DontDelete)); 3685 desc.set_configurable(!(attributes & v8::DontDelete));
3686 desc.set_value(value_obj); 3686 desc.set_value(value_obj);
3687 Maybe<bool> success = i::JSReceiver::DefineOwnProperty( 3687 Maybe<bool> success = i::JSReceiver::DefineOwnProperty(
3688 isolate, self, key_obj, &desc, i::Object::DONT_THROW); 3688 isolate, self, key_obj, &desc, i::Object::DONT_THROW);
3689 // Even though we said DONT_THROW, there might be accessors that do throw. 3689 // Even though we said DONT_THROW, there might be accessors that do throw.
3690 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 3690 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3691 return success; 3691 return success;
3692 } 3692 }
3693 3693
3694 Maybe<bool> v8::Object::DefineProperty(v8::Local<v8::Context> context,
3695 v8::Local<Name> key,
3696 const PropertyDescriptor* descriptor) {
3697 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Object, DefineProperty, bool);
3698 auto self = Utils::OpenHandle(this);
3699 auto key_obj = Utils::OpenHandle(*key);
3700
3701 if (self->IsAccessCheckNeeded() &&
Toon Verwaest 2016/08/18 07:25:39 I'm pretty sure that access is properly checked in
Franzi 2016/08/18 09:56:24 You're right. Deleted in in v8::Object::DefineOwnP
3702 !isolate->MayAccess(handle(isolate->context()),
3703 i::Handle<i::JSObject>::cast(self))) {
3704 isolate->ReportFailedAccessCheck(i::Handle<i::JSObject>::cast(self));
3705 return Nothing<bool>();
3706 }
3707
3708 i::PropertyDescriptor desc;
3709 if (descriptor->has_value()) {
3710 if (descriptor->value().IsEmpty()) {
3711 desc.set_value(isolate->factory()->undefined_value());
3712 } else {
3713 desc.set_value(Utils::OpenHandle(*descriptor->value()));
3714 }
3715 }
3716 if (descriptor->has_get()) {
3717 if (descriptor->get().IsEmpty()) {
3718 desc.set_get(isolate->factory()->undefined_value());
3719 } else {
3720 desc.set_get(Utils::OpenHandle(*descriptor->get()));
3721 }
3722 }
3723 if (descriptor->has_set()) {
3724 if (descriptor->set().IsEmpty()) {
3725 desc.set_set(isolate->factory()->undefined_value());
3726 } else {
3727 desc.set_set(Utils::OpenHandle(*descriptor->set()));
3728 }
3729 }
3730 if (descriptor->has_enumerable()) {
3731 desc.set_enumerable(descriptor->enumerable());
3732 }
3733 if (descriptor->has_configurable()) {
3734 desc.set_configurable(descriptor->configurable());
3735 }
3736 if (descriptor->has_writable()) {
3737 desc.set_writable(descriptor->writable());
3738 }
3739
3740 auto success = i::JSReceiver::DefineOwnProperty(isolate, self, key_obj, &desc,
3741 i::Object::DONT_THROW);
3742 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3743 return success;
3744 }
3694 3745
3695 MUST_USE_RESULT 3746 MUST_USE_RESULT
3696 static i::MaybeHandle<i::Object> DefineObjectProperty( 3747 static i::MaybeHandle<i::Object> DefineObjectProperty(
3697 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key, 3748 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key,
3698 i::Handle<i::Object> value, i::PropertyAttributes attrs) { 3749 i::Handle<i::Object> value, i::PropertyAttributes attrs) {
3699 i::Isolate* isolate = js_object->GetIsolate(); 3750 i::Isolate* isolate = js_object->GetIsolate();
3700 bool success = false; 3751 bool success = false;
3701 i::LookupIterator it = i::LookupIterator::PropertyOrElement( 3752 i::LookupIterator it = i::LookupIterator::PropertyOrElement(
3702 isolate, js_object, key, &success, i::LookupIterator::OWN); 3753 isolate, js_object, key, &success, i::LookupIterator::OWN);
3703 if (!success) return i::MaybeHandle<i::Object>(); 3754 if (!success) return i::MaybeHandle<i::Object>();
(...skipping 5313 matching lines...) Expand 10 before | Expand all | Expand 10 after
9017 Address callback_address = 9068 Address callback_address =
9018 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 9069 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
9019 VMState<EXTERNAL> state(isolate); 9070 VMState<EXTERNAL> state(isolate);
9020 ExternalCallbackScope call_scope(isolate, callback_address); 9071 ExternalCallbackScope call_scope(isolate, callback_address);
9021 callback(info); 9072 callback(info);
9022 } 9073 }
9023 9074
9024 9075
9025 } // namespace internal 9076 } // namespace internal
9026 } // namespace v8 9077 } // namespace v8
OLDNEW
« include/v8.h ('K') | « include/v8.h ('k') | src/counters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698