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

Side by Side Diff: src/api.cc

Issue 1178503004: Replace SetObjectProperty / DefineObjectProperty with less powerful alternatives where relevant. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 6 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
« no previous file with comments | « no previous file | src/api-natives.cc » ('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 3517 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = i::Runtime::DefineObjectProperty( 3538 has_pending_exception = i::JSObject::SetOwnPropertyIgnoreAttributes(
3539 self, key_obj, value_obj, NONE).is_null(); 3539 self, key_obj, value_obj, NONE).is_null();
3540 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 3540 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3541 return Just(true); 3541 return Just(true);
3542 } 3542 }
3543 3543
3544 3544
3545 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, 3545 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context,
3546 uint32_t index, 3546 uint32_t index,
3547 v8::Local<Value> value) { 3547 v8::Local<Value> value) {
3548 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", 3548 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()",
(...skipping 17 matching lines...) Expand all
3566 value, v8::None); 3566 value, v8::None);
3567 } 3567 }
3568 } 3568 }
3569 3569
3570 Maybe<PropertyAttributes> attributes = 3570 Maybe<PropertyAttributes> attributes =
3571 i::JSReceiver::GetOwnElementAttributes(self, index); 3571 i::JSReceiver::GetOwnElementAttributes(self, index);
3572 if (attributes.IsJust() && attributes.FromJust() & DONT_DELETE) { 3572 if (attributes.IsJust() && attributes.FromJust() & DONT_DELETE) {
3573 return Just(false); 3573 return Just(false);
3574 } 3574 }
3575 3575
3576 has_pending_exception = i::Runtime::DefineObjectProperty( 3576 has_pending_exception = i::JSObject::SetOwnElementIgnoreAttributes(
3577 self, isolate->factory()->Uint32ToString(index), 3577 self, index, value_obj, NONE).is_null();
3578 value_obj, NONE).is_null();
3579 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 3578 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3580 return Just(true); 3579 return Just(true);
3581 } 3580 }
3582 3581
3583 3582
3584 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context, 3583 Maybe<bool> v8::Object::DefineOwnProperty(v8::Local<v8::Context> context,
3585 v8::Local<Name> key, 3584 v8::Local<Name> key,
3586 v8::Local<Value> value, 3585 v8::Local<Value> value,
3587 v8::PropertyAttribute attributes) { 3586 v8::PropertyAttribute attributes) {
3588 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DefineOwnProperty()", 3587 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::DefineOwnProperty()",
(...skipping 17 matching lines...) Expand all
3606 i::Handle<i::Object> result; 3605 i::Handle<i::Object> result;
3607 has_pending_exception = 3606 has_pending_exception =
3608 !CallV8HeapFunction(isolate, "$objectDefineOwnProperty", 3607 !CallV8HeapFunction(isolate, "$objectDefineOwnProperty",
3609 isolate->factory()->undefined_value(), 3608 isolate->factory()->undefined_value(),
3610 arraysize(args), args).ToHandle(&result); 3609 arraysize(args), args).ToHandle(&result);
3611 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 3610 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3612 return Just(result->BooleanValue()); 3611 return Just(result->BooleanValue());
3613 } 3612 }
3614 3613
3615 3614
3615 MUST_USE_RESULT
3616 static i::MaybeHandle<i::Object> DefineObjectProperty(
3617 i::Handle<i::JSObject> js_object, i::Handle<i::Object> key,
3618 i::Handle<i::Object> value, PropertyAttributes attrs) {
3619 i::Isolate* isolate = js_object->GetIsolate();
3620 // Check if the given key is an array index.
3621 uint32_t index = 0;
3622 if (key->ToArrayIndex(&index)) {
3623 return i::JSObject::SetOwnElementIgnoreAttributes(js_object, index, value,
3624 attrs);
3625 }
3626
3627 i::Handle<i::Name> name;
3628 if (key->IsName()) {
3629 name = i::Handle<i::Name>::cast(key);
3630 } else {
3631 // Call-back into JavaScript to convert the key to a string.
3632 i::Handle<i::Object> converted;
3633 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, converted,
3634 i::Execution::ToString(isolate, key),
3635 i::MaybeHandle<i::Object>());
3636 name = i::Handle<i::String>::cast(converted);
3637 }
3638
3639 return i::JSObject::DefinePropertyOrElement(js_object, name, value, attrs);
3640 }
3641
3642
3616 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, 3643 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context,
3617 v8::Local<Value> key, v8::Local<Value> value, 3644 v8::Local<Value> key, v8::Local<Value> value,
3618 v8::PropertyAttribute attribs) { 3645 v8::PropertyAttribute attribs) {
3619 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); 3646 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool);
3620 auto self = Utils::OpenHandle(this); 3647 auto self = Utils::OpenHandle(this);
3621 auto key_obj = Utils::OpenHandle(*key); 3648 auto key_obj = Utils::OpenHandle(*key);
3622 auto value_obj = Utils::OpenHandle(*value); 3649 auto value_obj = Utils::OpenHandle(*value);
3623 has_pending_exception = i::Runtime::DefineObjectProperty( 3650 has_pending_exception =
3624 self, 3651 DefineObjectProperty(self, key_obj, value_obj,
3625 key_obj, 3652 static_cast<PropertyAttributes>(attribs)).is_null();
3626 value_obj,
3627 static_cast<PropertyAttributes>(attribs)).is_null();
3628 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); 3653 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
3629 return Just(true); 3654 return Just(true);
3630 } 3655 }
3631 3656
3632 3657
3633 bool v8::Object::ForceSet(v8::Handle<Value> key, v8::Handle<Value> value, 3658 bool v8::Object::ForceSet(v8::Handle<Value> key, v8::Handle<Value> value,
3634 v8::PropertyAttribute attribs) { 3659 v8::PropertyAttribute attribs) {
3635 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3660 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3636 PREPARE_FOR_EXECUTION_GENERIC(isolate, Local<Context>(), 3661 PREPARE_FOR_EXECUTION_GENERIC(isolate, Local<Context>(),
3637 "v8::Object::ForceSet", false, i::HandleScope, 3662 "v8::Object::ForceSet", false, i::HandleScope,
3638 false); 3663 false);
3639 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3664 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3640 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 3665 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3641 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); 3666 i::Handle<i::Object> value_obj = Utils::OpenHandle(*value);
3642 has_pending_exception = 3667 has_pending_exception =
3643 i::Runtime::DefineObjectProperty(self, key_obj, value_obj, 3668 DefineObjectProperty(self, key_obj, value_obj,
3644 static_cast<PropertyAttributes>(attribs)) 3669 static_cast<PropertyAttributes>(attribs)).is_null();
3645 .is_null();
3646 EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, false); 3670 EXCEPTION_BAILOUT_CHECK_SCOPED(isolate, false);
3647 return true; 3671 return true;
3648 } 3672 }
3649 3673
3650 3674
3651 namespace { 3675 namespace {
3652 3676
3653 i::MaybeHandle<i::Object> DeleteObjectProperty( 3677 i::MaybeHandle<i::Object> DeleteObjectProperty(
3654 i::Isolate* isolate, i::Handle<i::JSReceiver> receiver, 3678 i::Isolate* isolate, i::Handle<i::JSReceiver> receiver,
3655 i::Handle<i::Object> key, i::LanguageMode language_mode) { 3679 i::Handle<i::Object> key, i::LanguageMode language_mode) {
(...skipping 4761 matching lines...) Expand 10 before | Expand all | Expand 10 after
8417 Address callback_address = 8441 Address callback_address =
8418 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8442 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8419 VMState<EXTERNAL> state(isolate); 8443 VMState<EXTERNAL> state(isolate);
8420 ExternalCallbackScope call_scope(isolate, callback_address); 8444 ExternalCallbackScope call_scope(isolate, callback_address);
8421 callback(info); 8445 callback(info);
8422 } 8446 }
8423 8447
8424 8448
8425 } // namespace internal 8449 } // namespace internal
8426 } // namespace v8 8450 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/api-natives.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698