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 3443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3454 return Just(true); | 3454 return Just(true); |
3455 } | 3455 } |
3456 | 3456 |
3457 | 3457 |
3458 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { | 3458 bool v8::Object::Set(uint32_t index, v8::Handle<Value> value) { |
3459 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 3459 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
3460 return Set(context, index, value).FromMaybe(false); | 3460 return Set(context, index, value).FromMaybe(false); |
3461 } | 3461 } |
3462 | 3462 |
3463 | 3463 |
| 3464 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, |
| 3465 v8::Local<Name> key, |
| 3466 v8::Local<Value> value) { |
| 3467 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", |
| 3468 bool); |
| 3469 auto self = Utils::OpenHandle(this); |
| 3470 auto key_obj = Utils::OpenHandle(*key); |
| 3471 auto value_obj = Utils::OpenHandle(*value); |
| 3472 |
| 3473 if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) { |
| 3474 isolate->ReportFailedAccessCheck(self); |
| 3475 return Nothing<bool>(); |
| 3476 } |
| 3477 |
| 3478 if (!self->IsExtensible()) return Just(false); |
| 3479 |
| 3480 uint32_t index = 0; |
| 3481 if (key_obj->AsArrayIndex(&index)) { |
| 3482 return CreateDataProperty(context, index, value); |
| 3483 } |
| 3484 |
| 3485 // Special case for Array.length. |
| 3486 if (self->IsJSArray() && |
| 3487 key->StrictEquals(Utils::ToLocal(isolate->factory()->length_string()))) { |
| 3488 // Length is not configurable, however, CreateDataProperty always attempts |
| 3489 // to create a configurable property, so we just fail here. |
| 3490 return Just(false); |
| 3491 } |
| 3492 |
| 3493 i::LookupIterator it(self, key_obj, i::LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 3494 if (it.IsFound() && it.state() == i::LookupIterator::ACCESS_CHECK) { |
| 3495 DCHECK(isolate->MayAccess(self)); |
| 3496 it.Next(); |
| 3497 } |
| 3498 |
| 3499 if (it.state() == i::LookupIterator::DATA || |
| 3500 it.state() == i::LookupIterator::ACCESSOR) { |
| 3501 if (!it.IsConfigurable()) return Just(false); |
| 3502 |
| 3503 if (it.state() == i::LookupIterator::ACCESSOR) { |
| 3504 has_pending_exception = i::JSObject::SetOwnPropertyIgnoreAttributes( |
| 3505 self, key_obj, value_obj, NONE, |
| 3506 i::JSObject::DONT_FORCE_FIELD).is_null(); |
| 3507 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 3508 return Just(true); |
| 3509 } |
| 3510 } |
| 3511 |
| 3512 has_pending_exception = i::Runtime::DefineObjectProperty( |
| 3513 self, key_obj, value_obj, NONE).is_null(); |
| 3514 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 3515 return Just(true); |
| 3516 } |
| 3517 |
| 3518 |
| 3519 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, |
| 3520 uint32_t index, |
| 3521 v8::Local<Value> value) { |
| 3522 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", |
| 3523 bool); |
| 3524 auto self = Utils::OpenHandle(this); |
| 3525 auto value_obj = Utils::OpenHandle(*value); |
| 3526 |
| 3527 if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) { |
| 3528 isolate->ReportFailedAccessCheck(self); |
| 3529 return Nothing<bool>(); |
| 3530 } |
| 3531 |
| 3532 if (!self->IsExtensible()) return Just(false); |
| 3533 |
| 3534 if (self->IsJSArray()) { |
| 3535 size_t length = |
| 3536 i::NumberToSize(isolate, i::Handle<i::JSArray>::cast(self)->length()); |
| 3537 if (index >= length) { |
| 3538 i::Handle<i::Object> args[] = { |
| 3539 self, isolate->factory()->Uint32ToString(index), value_obj}; |
| 3540 i::Handle<i::Object> result; |
| 3541 has_pending_exception = |
| 3542 !CallV8HeapFunction(isolate, "$objectDefineArrayProperty", |
| 3543 isolate->factory()->undefined_value(), |
| 3544 arraysize(args), args).ToHandle(&result); |
| 3545 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 3546 return Just(result->BooleanValue()); |
| 3547 } |
| 3548 } |
| 3549 |
| 3550 Maybe<PropertyAttributes> attributes = |
| 3551 i::JSReceiver::GetOwnElementAttribute(self, index); |
| 3552 if (attributes.IsJust() && attributes.FromJust() & DONT_DELETE) { |
| 3553 return Just(false); |
| 3554 } |
| 3555 |
| 3556 has_pending_exception = i::Runtime::DefineObjectProperty( |
| 3557 self, isolate->factory()->Uint32ToString(index), |
| 3558 value_obj, NONE).is_null(); |
| 3559 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); |
| 3560 return Just(true); |
| 3561 } |
| 3562 |
| 3563 |
3464 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, | 3564 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, |
3465 v8::Local<Value> key, v8::Local<Value> value, | 3565 v8::Local<Value> key, v8::Local<Value> value, |
3466 v8::PropertyAttribute attribs) { | 3566 v8::PropertyAttribute attribs) { |
3467 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); | 3567 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); |
3468 auto self = Utils::OpenHandle(this); | 3568 auto self = Utils::OpenHandle(this); |
3469 auto key_obj = Utils::OpenHandle(*key); | 3569 auto key_obj = Utils::OpenHandle(*key); |
3470 auto value_obj = Utils::OpenHandle(*value); | 3570 auto value_obj = Utils::OpenHandle(*value); |
3471 has_pending_exception = i::Runtime::DefineObjectProperty( | 3571 has_pending_exception = i::Runtime::DefineObjectProperty( |
3472 self, | 3572 self, |
3473 key_obj, | 3573 key_obj, |
(...skipping 4635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8109 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8209 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8110 Address callback_address = | 8210 Address callback_address = |
8111 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8211 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8112 VMState<EXTERNAL> state(isolate); | 8212 VMState<EXTERNAL> state(isolate); |
8113 ExternalCallbackScope call_scope(isolate, callback_address); | 8213 ExternalCallbackScope call_scope(isolate, callback_address); |
8114 callback(info); | 8214 callback(info); |
8115 } | 8215 } |
8116 | 8216 |
8117 | 8217 |
8118 } } // namespace v8::internal | 8218 } } // namespace v8::internal |
OLD | NEW |