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()", | |
Toon Verwaest
2015/05/26 19:40:55
It seems like this is more of a DefineDataProperty
jochen (gone - plz use gerrit)
2015/05/27 07:28:30
it's the name of the JS method.
| |
3468 bool); | |
3469 auto self = Utils::OpenHandle(this); | |
Toon Verwaest
2015/05/26 19:40:55
Note that I'm in the process of merging all named
| |
3470 auto key_obj = Utils::OpenHandle(*key); | |
3471 auto value_obj = Utils::OpenHandle(*value); | |
3472 if (!self->IsExtensible()) return Just(false); | |
3473 | |
3474 uint32_t index = 0; | |
3475 if (key_obj->AsArrayIndex(&index)) { | |
3476 return CreateDataProperty(context, index, value); | |
3477 } | |
3478 | |
3479 // Special case for Array.length. | |
jochen (gone - plz use gerrit)
2015/05/26 16:49:44
Array.prototype.length is not configurable, so thi
Toon Verwaest
2015/05/26 19:40:55
Shouldn't this be allowed to modify the value of t
jochen (gone - plz use gerrit)
2015/05/27 07:28:29
see v8natives.js
| |
3480 if (self->IsJSArray() && | |
3481 key->StrictEquals(Utils::ToLocal( | |
3482 isolate->factory()->NewStringFromStaticChars("length")))) { | |
3483 i::Handle<i::Object> args[] = {self, key_obj, value_obj}; | |
3484 i::Handle<i::Object> result; | |
3485 has_pending_exception = | |
3486 !CallV8HeapFunction(isolate, "$objectDefineArrayProperty", | |
3487 isolate->factory()->undefined_value(), | |
3488 arraysize(args), args).ToHandle(&result); | |
3489 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
3490 return Just(true); | |
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 if (isolate->MayAccess(self)) return Just(false); | |
noordhuis
2015/05/26 17:22:27
Should this be `if (!isolate->MayAccess(self)) ...
Toon Verwaest
2015/05/26 19:40:55
Yes. Seems like a missing test.
jochen (gone - plz use gerrit)
2015/05/27 07:28:30
done
| |
3496 it.Next(); | |
3497 } | |
3498 | |
3499 if (it.state() == i::LookupIterator::DATA || | |
3500 it.state() == i::LookupIterator::ACCESSOR) { | |
3501 if (it.property_details().attributes() & DONT_DELETE) 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 | |
3513 has_pending_exception = i::Runtime::DefineObjectProperty( | |
3514 self, key_obj, value_obj, NONE).is_null(); | |
3515 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
3516 return Just(true); | |
3517 } | |
3518 | |
3519 | |
3520 Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, | |
3521 uint32_t index, | |
3522 v8::Local<Value> value) { | |
3523 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::CreateDataProperty()", | |
3524 bool); | |
3525 auto self = Utils::OpenHandle(this); | |
3526 auto value_obj = Utils::OpenHandle(*value); | |
3527 if (!self->IsExtensible()) return Just(false); | |
3528 | |
3529 if (self->IsJSArray()) { | |
3530 size_t length = | |
3531 i::NumberToSize(isolate, i::Handle<i::JSArray>::cast(self)->length()); | |
3532 if (index >= length) { | |
3533 i::Handle<i::Object> args[] = { | |
3534 self, isolate->factory()->Uint32ToString(index), value_obj}; | |
3535 i::Handle<i::Object> result; | |
3536 has_pending_exception = | |
3537 !CallV8HeapFunction(isolate, "$objectDefineArrayProperty", | |
3538 isolate->factory()->undefined_value(), | |
3539 arraysize(args), args).ToHandle(&result); | |
3540 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
3541 return Just(true); | |
3542 } | |
3543 } | |
3544 | |
3545 if (self->IsAccessCheckNeeded() && !isolate->MayAccess(self)) | |
3546 return Just(false); | |
Toon Verwaest
2015/05/26 19:40:55
Add {} if on new line
jochen (gone - plz use gerrit)
2015/05/27 07:28:29
done
| |
3547 | |
3548 Maybe<PropertyAttributes> attributes = | |
3549 i::JSObject::GetElementAttributeWithReceiver(self, self, index, false); | |
3550 if (attributes.IsJust() && attributes.FromJust() != ABSENT) { | |
3551 if (attributes.FromJust() & DONT_DELETE) return Just(false); | |
3552 | |
3553 | |
3554 has_pending_exception = | |
3555 i::JSObject::SetOwnPropertyIgnoreAttributes( | |
3556 self, isolate->factory()->Uint32ToString(index), value_obj, NONE, | |
Toon Verwaest
2015/05/26 19:40:55
You cannot use SetOwn... For elements at this mome
jochen (gone - plz use gerrit)
2015/05/27 07:28:29
this code path is covered by the test that sets ar
Toon Verwaest
2015/05/27 08:03:57
I can guarantee you that that code path doesn't wo
| |
3557 i::JSObject::DONT_FORCE_FIELD).is_null(); | |
3558 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
3559 return Just(true); | |
3560 } | |
3561 | |
3562 | |
3563 has_pending_exception = i::Runtime::DefineObjectProperty( | |
3564 self, isolate->factory()->Uint32ToString(index), | |
3565 value_obj, NONE).is_null(); | |
3566 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool); | |
3567 return Just(true); | |
3568 } | |
3569 | |
3570 | |
3464 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, | 3571 Maybe<bool> v8::Object::ForceSet(v8::Local<v8::Context> context, |
3465 v8::Local<Value> key, v8::Local<Value> value, | 3572 v8::Local<Value> key, v8::Local<Value> value, |
3466 v8::PropertyAttribute attribs) { | 3573 v8::PropertyAttribute attribs) { |
3467 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); | 3574 PREPARE_FOR_EXECUTION_PRIMITIVE(context, "v8::Object::Set()", bool); |
3468 auto self = Utils::OpenHandle(this); | 3575 auto self = Utils::OpenHandle(this); |
3469 auto key_obj = Utils::OpenHandle(*key); | 3576 auto key_obj = Utils::OpenHandle(*key); |
3470 auto value_obj = Utils::OpenHandle(*value); | 3577 auto value_obj = Utils::OpenHandle(*value); |
3471 has_pending_exception = i::Runtime::DefineObjectProperty( | 3578 has_pending_exception = i::Runtime::DefineObjectProperty( |
3472 self, | 3579 self, |
3473 key_obj, | 3580 key_obj, |
(...skipping 4635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8109 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8216 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8110 Address callback_address = | 8217 Address callback_address = |
8111 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8218 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8112 VMState<EXTERNAL> state(isolate); | 8219 VMState<EXTERNAL> state(isolate); |
8113 ExternalCallbackScope call_scope(isolate, callback_address); | 8220 ExternalCallbackScope call_scope(isolate, callback_address); |
8114 callback(info); | 8221 callback(info); |
8115 } | 8222 } |
8116 | 8223 |
8117 | 8224 |
8118 } } // namespace v8::internal | 8225 } } // namespace v8::internal |
OLD | NEW |