OLD | NEW |
---|---|
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <iomanip> | 8 #include <iomanip> |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 4647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4658 THROW_NEW_ERROR( | 4658 THROW_NEW_ERROR( |
4659 isolate, | 4659 isolate, |
4660 NewTypeError(MessageTemplate::kProxyHandlerDeleteFailed, handler), | 4660 NewTypeError(MessageTemplate::kProxyHandlerDeleteFailed, handler), |
4661 Object); | 4661 Object); |
4662 } | 4662 } |
4663 return isolate->factory()->ToBoolean(result_bool); | 4663 return isolate->factory()->ToBoolean(result_bool); |
4664 } | 4664 } |
4665 | 4665 |
4666 | 4666 |
4667 Maybe<PropertyAttributes> JSProxy::GetPropertyAttributesWithHandler( | 4667 Maybe<PropertyAttributes> JSProxy::GetPropertyAttributesWithHandler( |
4668 Handle<JSProxy> proxy, Handle<Object> receiver, Handle<Name> name) { | 4668 LookupIterator* it) { |
4669 Isolate* isolate = proxy->GetIsolate(); | 4669 Isolate* isolate = it->isolate(); |
4670 HandleScope scope(isolate); | 4670 HandleScope scope(isolate); |
4671 | 4671 PropertyDescriptor desc; |
4672 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 4672 bool found = JSProxy::GetOwnPropertyDescriptor(it, &desc); |
4673 if (name->IsSymbol()) return Just(ABSENT); | 4673 if (isolate->has_pending_exception()) return Nothing<PropertyAttributes>(); |
4674 | 4674 if (!found) return Just(ABSENT); |
4675 Handle<Object> args[] = { name }; | 4675 return Just(desc.ToAttributes()); |
4676 Handle<Object> result; | |
4677 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
4678 isolate, result, proxy->CallTrap(proxy, "getPropertyDescriptor", | |
4679 Handle<Object>(), arraysize(args), args), | |
4680 Nothing<PropertyAttributes>()); | |
4681 | |
4682 if (result->IsUndefined()) return Just(ABSENT); | |
4683 | |
4684 Handle<Object> argv[] = { result }; | |
4685 Handle<Object> desc; | |
4686 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
4687 isolate, desc, | |
4688 Execution::Call(isolate, isolate->to_complete_property_descriptor(), | |
4689 result, arraysize(argv), argv), | |
4690 Nothing<PropertyAttributes>()); | |
4691 | |
4692 // Convert result to PropertyAttributes. | |
4693 Handle<String> enum_n = isolate->factory()->InternalizeOneByteString( | |
4694 STATIC_CHAR_VECTOR("enumerable_")); | |
4695 Handle<Object> enumerable; | |
4696 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, enumerable, | |
4697 Object::GetProperty(desc, enum_n), | |
4698 Nothing<PropertyAttributes>()); | |
4699 Handle<String> conf_n = isolate->factory()->InternalizeOneByteString( | |
4700 STATIC_CHAR_VECTOR("configurable_")); | |
4701 Handle<Object> configurable; | |
4702 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, configurable, | |
4703 Object::GetProperty(desc, conf_n), | |
4704 Nothing<PropertyAttributes>()); | |
4705 Handle<String> writ_n = isolate->factory()->InternalizeOneByteString( | |
4706 STATIC_CHAR_VECTOR("writable_")); | |
4707 Handle<Object> writable; | |
4708 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, writable, | |
4709 Object::GetProperty(desc, writ_n), | |
4710 Nothing<PropertyAttributes>()); | |
4711 if (!writable->BooleanValue()) { | |
4712 Handle<String> set_n = isolate->factory()->InternalizeOneByteString( | |
4713 STATIC_CHAR_VECTOR("set_")); | |
4714 Handle<Object> setter; | |
4715 ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, setter, | |
4716 Object::GetProperty(desc, set_n), | |
4717 Nothing<PropertyAttributes>()); | |
4718 writable = isolate->factory()->ToBoolean(!setter->IsUndefined()); | |
4719 } | |
4720 | |
4721 if (configurable->IsFalse()) { | |
4722 Handle<Object> handler(proxy->handler(), isolate); | |
4723 Handle<String> trap = isolate->factory()->InternalizeOneByteString( | |
4724 STATIC_CHAR_VECTOR("getPropertyDescriptor")); | |
4725 Handle<Object> error = isolate->factory()->NewTypeError( | |
4726 MessageTemplate::kProxyPropNotConfigurable, handler, name, trap); | |
4727 isolate->Throw(*error); | |
4728 return Nothing<PropertyAttributes>(); | |
4729 } | |
4730 | |
4731 int attributes = NONE; | |
4732 if (!enumerable->BooleanValue()) attributes |= DONT_ENUM; | |
4733 if (!configurable->BooleanValue()) attributes |= DONT_DELETE; | |
4734 if (!writable->BooleanValue()) attributes |= READ_ONLY; | |
4735 return Just(static_cast<PropertyAttributes>(attributes)); | |
4736 } | 4676 } |
4737 | 4677 |
4738 | 4678 |
4739 MaybeHandle<Object> JSProxy::CallTrap(Handle<JSProxy> proxy, | 4679 MaybeHandle<Object> JSProxy::CallTrap(Handle<JSProxy> proxy, |
4740 const char* name, | 4680 const char* name, |
4741 Handle<Object> derived, | 4681 Handle<Object> derived, |
4742 int argc, | 4682 int argc, |
4743 Handle<Object> argv[]) { | 4683 Handle<Object> argv[]) { |
4744 Isolate* isolate = proxy->GetIsolate(); | 4684 Isolate* isolate = proxy->GetIsolate(); |
4745 Handle<Object> handler(proxy->handler(), isolate); | 4685 Handle<Object> handler(proxy->handler(), isolate); |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5108 | 5048 |
5109 | 5049 |
5110 Maybe<PropertyAttributes> JSReceiver::GetPropertyAttributes( | 5050 Maybe<PropertyAttributes> JSReceiver::GetPropertyAttributes( |
5111 LookupIterator* it) { | 5051 LookupIterator* it) { |
5112 for (; it->IsFound(); it->Next()) { | 5052 for (; it->IsFound(); it->Next()) { |
5113 switch (it->state()) { | 5053 switch (it->state()) { |
5114 case LookupIterator::NOT_FOUND: | 5054 case LookupIterator::NOT_FOUND: |
5115 case LookupIterator::TRANSITION: | 5055 case LookupIterator::TRANSITION: |
5116 UNREACHABLE(); | 5056 UNREACHABLE(); |
5117 case LookupIterator::JSPROXY: | 5057 case LookupIterator::JSPROXY: |
5118 return JSProxy::GetPropertyAttributesWithHandler( | 5058 return JSProxy::GetPropertyAttributesWithHandler(it); |
5119 it->GetHolder<JSProxy>(), it->GetReceiver(), it->GetName()); | |
5120 case LookupIterator::INTERCEPTOR: { | 5059 case LookupIterator::INTERCEPTOR: { |
5121 Maybe<PropertyAttributes> result = | 5060 Maybe<PropertyAttributes> result = |
5122 JSObject::GetPropertyAttributesWithInterceptor(it); | 5061 JSObject::GetPropertyAttributesWithInterceptor(it); |
5123 if (!result.IsJust()) return result; | 5062 if (!result.IsJust()) return result; |
5124 if (result.FromJust() != ABSENT) return result; | 5063 if (result.FromJust() != ABSENT) return result; |
5125 break; | 5064 break; |
5126 } | 5065 } |
5127 case LookupIterator::ACCESS_CHECK: | 5066 case LookupIterator::ACCESS_CHECK: |
5128 if (it->HasAccess()) break; | 5067 if (it->HasAccess()) break; |
5129 return JSObject::GetPropertyAttributesWithFailedAccessCheck(it); | 5068 return JSObject::GetPropertyAttributesWithFailedAccessCheck(it); |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6007 return Object::ToString(isolate, key); | 5946 return Object::ToString(isolate, key); |
6008 } | 5947 } |
6009 | 5948 |
6010 | 5949 |
6011 // ES6 19.1.2.4 | 5950 // ES6 19.1.2.4 |
6012 // static | 5951 // static |
6013 Object* JSReceiver::DefineProperty(Isolate* isolate, Handle<Object> object, | 5952 Object* JSReceiver::DefineProperty(Isolate* isolate, Handle<Object> object, |
6014 Handle<Object> key, | 5953 Handle<Object> key, |
6015 Handle<Object> attributes) { | 5954 Handle<Object> attributes) { |
6016 // 1. If Type(O) is not Object, throw a TypeError exception. | 5955 // 1. If Type(O) is not Object, throw a TypeError exception. |
6017 // TODO(jkummerow): Implement Proxy support, change to "IsSpecObject". | 5956 if (!object->IsSpecObject()) { |
6018 if (!object->IsJSObject()) { | |
6019 Handle<String> fun_name = | 5957 Handle<String> fun_name = |
6020 isolate->factory()->InternalizeUtf8String("Object.defineProperty"); | 5958 isolate->factory()->InternalizeUtf8String("Object.defineProperty"); |
6021 THROW_NEW_ERROR_RETURN_FAILURE( | 5959 THROW_NEW_ERROR_RETURN_FAILURE( |
6022 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); | 5960 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); |
6023 } | 5961 } |
6024 // 2. Let key be ToPropertyKey(P). | 5962 // 2. Let key be ToPropertyKey(P). |
6025 // 3. ReturnIfAbrupt(key). | 5963 // 3. ReturnIfAbrupt(key). |
6026 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, ToPropertyKey(isolate, key)); | 5964 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key, ToPropertyKey(isolate, key)); |
6027 // 4. Let desc be ToPropertyDescriptor(Attributes). | 5965 // 4. Let desc be ToPropertyDescriptor(Attributes). |
6028 // 5. ReturnIfAbrupt(desc). | 5966 // 5. ReturnIfAbrupt(desc). |
6029 PropertyDescriptor desc; | 5967 PropertyDescriptor desc; |
6030 if (!PropertyDescriptor::ToPropertyDescriptor(isolate, attributes, &desc)) { | 5968 if (!PropertyDescriptor::ToPropertyDescriptor(isolate, attributes, &desc)) { |
6031 return isolate->heap()->exception(); | 5969 return isolate->heap()->exception(); |
6032 } | 5970 } |
6033 // 6. Let success be DefinePropertyOrThrow(O,key, desc). | 5971 // 6. Let success be DefinePropertyOrThrow(O,key, desc). |
6034 bool success = DefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, | 5972 bool success = DefineOwnProperty(isolate, Handle<JSReceiver>::cast(object), |
6035 &desc, THROW_ON_ERROR); | 5973 key, &desc, THROW_ON_ERROR); |
6036 // 7. ReturnIfAbrupt(success). | 5974 // 7. ReturnIfAbrupt(success). |
6037 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 5975 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
6038 CHECK(success == true); | 5976 CHECK(success == true); |
6039 // 8. Return O. | 5977 // 8. Return O. |
6040 return *object; | 5978 return *object; |
6041 } | 5979 } |
6042 | 5980 |
6043 | 5981 |
6044 // ES6 19.1.2.3.1 | 5982 // ES6 19.1.2.3.1 |
6045 // static | 5983 // static |
6046 Object* JSReceiver::DefineProperties(Isolate* isolate, Handle<Object> object, | 5984 Object* JSReceiver::DefineProperties(Isolate* isolate, Handle<Object> object, |
6047 Handle<Object> properties) { | 5985 Handle<Object> properties) { |
6048 // 1. If Type(O) is not Object, throw a TypeError exception. | 5986 // 1. If Type(O) is not Object, throw a TypeError exception. |
6049 // TODO(jkummerow): Implement Proxy support, change to "IsSpecObject". | 5987 if (!object->IsSpecObject()) { |
6050 if (!object->IsJSObject()) { | |
6051 Handle<String> fun_name = | 5988 Handle<String> fun_name = |
6052 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); | 5989 isolate->factory()->InternalizeUtf8String("Object.defineProperties"); |
6053 THROW_NEW_ERROR_RETURN_FAILURE( | 5990 THROW_NEW_ERROR_RETURN_FAILURE( |
6054 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); | 5991 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, fun_name)); |
6055 } | 5992 } |
6056 // 2. Let props be ToObject(Properties). | 5993 // 2. Let props be ToObject(Properties). |
6057 // 3. ReturnIfAbrupt(props). | 5994 // 3. ReturnIfAbrupt(props). |
6058 Handle<JSReceiver> props; | 5995 Handle<JSReceiver> props; |
6059 if (!Object::ToObject(isolate, properties).ToHandle(&props)) { | 5996 if (!Object::ToObject(isolate, properties).ToHandle(&props)) { |
6060 THROW_NEW_ERROR_RETURN_FAILURE( | 5997 THROW_NEW_ERROR_RETURN_FAILURE( |
(...skipping 10 matching lines...) Expand all Loading... | |
6071 std::vector<PropertyDescriptor> descriptors(capacity); | 6008 std::vector<PropertyDescriptor> descriptors(capacity); |
6072 // 7. Repeat for each element nextKey of keys in List order, | 6009 // 7. Repeat for each element nextKey of keys in List order, |
6073 for (int i = 0; i < keys->length(); ++i) { | 6010 for (int i = 0; i < keys->length(); ++i) { |
6074 Handle<Object> next_key(keys->get(i), isolate); | 6011 Handle<Object> next_key(keys->get(i), isolate); |
6075 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey). | 6012 // 7a. Let propDesc be props.[[GetOwnProperty]](nextKey). |
6076 // 7b. ReturnIfAbrupt(propDesc). | 6013 // 7b. ReturnIfAbrupt(propDesc). |
6077 bool success = false; | 6014 bool success = false; |
6078 LookupIterator it = LookupIterator::PropertyOrElement( | 6015 LookupIterator it = LookupIterator::PropertyOrElement( |
6079 isolate, props, next_key, &success, LookupIterator::HIDDEN); | 6016 isolate, props, next_key, &success, LookupIterator::HIDDEN); |
6080 DCHECK(success); | 6017 DCHECK(success); |
6081 // TODO(jkummerow): Support JSProxies. Make sure we call the correct | 6018 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
6082 // getOwnPropertyDescriptor trap, and convert the result object to a | |
6083 // PropertyDescriptor. | |
6084 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); | |
6085 if (!maybe.IsJust()) return isolate->heap()->exception(); | 6019 if (!maybe.IsJust()) return isolate->heap()->exception(); |
6086 PropertyAttributes attrs = maybe.FromJust(); | 6020 PropertyAttributes attrs = maybe.FromJust(); |
6087 // 7c. If propDesc is not undefined and propDesc.[[Enumerable]] is true: | 6021 // 7c. If propDesc is not undefined and propDesc.[[Enumerable]] is true: |
6088 if (attrs == ABSENT) continue; | 6022 if (attrs == ABSENT) continue; |
6089 // GetKeys() only returns enumerable keys. | 6023 // GetKeys() only returns enumerable keys. |
6090 DCHECK((attrs & DONT_ENUM) == 0); | 6024 DCHECK((attrs & DONT_ENUM) == 0); |
6091 // 7c i. Let descObj be Get(props, nextKey). | 6025 // 7c i. Let descObj be Get(props, nextKey). |
6092 // 7c ii. ReturnIfAbrupt(descObj). | 6026 // 7c ii. ReturnIfAbrupt(descObj). |
6093 Handle<Object> desc_obj; | 6027 Handle<Object> desc_obj; |
6094 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, desc_obj, | 6028 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, desc_obj, |
6095 JSObject::GetProperty(&it)); | 6029 Object::GetProperty(&it)); |
6096 // 7c iii. Let desc be ToPropertyDescriptor(descObj). | 6030 // 7c iii. Let desc be ToPropertyDescriptor(descObj). |
6097 success = PropertyDescriptor::ToPropertyDescriptor(isolate, desc_obj, | 6031 success = PropertyDescriptor::ToPropertyDescriptor(isolate, desc_obj, |
6098 &descriptors[i]); | 6032 &descriptors[i]); |
6099 // 7c iv. ReturnIfAbrupt(desc). | 6033 // 7c iv. ReturnIfAbrupt(desc). |
6100 if (!success) return isolate->heap()->exception(); | 6034 if (!success) return isolate->heap()->exception(); |
6101 // 7c v. Append the pair (a two element List) consisting of nextKey and | 6035 // 7c v. Append the pair (a two element List) consisting of nextKey and |
6102 // desc to the end of descriptors. | 6036 // desc to the end of descriptors. |
6103 descriptors[i].set_name(next_key); | 6037 descriptors[i].set_name(next_key); |
6104 } | 6038 } |
6105 // 8. For each pair from descriptors in list order, | 6039 // 8. For each pair from descriptors in list order, |
6106 for (size_t i = 0; i < descriptors.size(); ++i) { | 6040 for (size_t i = 0; i < descriptors.size(); ++i) { |
6107 PropertyDescriptor* desc = &descriptors[i]; | 6041 PropertyDescriptor* desc = &descriptors[i]; |
6108 // 8a. Let P be the first element of pair. | 6042 // 8a. Let P be the first element of pair. |
6109 // 8b. Let desc be the second element of pair. | 6043 // 8b. Let desc be the second element of pair. |
6110 // 8c. Let status be DefinePropertyOrThrow(O, P, desc). | 6044 // 8c. Let status be DefinePropertyOrThrow(O, P, desc). |
6111 bool status = DefineOwnProperty(isolate, Handle<JSObject>::cast(object), | 6045 bool status = DefineOwnProperty(isolate, Handle<JSReceiver>::cast(object), |
6112 desc->name(), desc, THROW_ON_ERROR); | 6046 desc->name(), desc, THROW_ON_ERROR); |
6113 // 8d. ReturnIfAbrupt(status). | 6047 // 8d. ReturnIfAbrupt(status). |
6114 if (isolate->has_pending_exception()) return isolate->heap()->exception(); | 6048 if (isolate->has_pending_exception()) return isolate->heap()->exception(); |
6115 CHECK(status == true); | 6049 CHECK(status == true); |
6116 } | 6050 } |
6117 // 9. Return o. | 6051 // 9. Return o. |
6118 return *object; | 6052 return *object; |
6119 } | 6053 } |
6120 | 6054 |
6121 | 6055 |
6122 // static | 6056 // static |
6123 bool JSReceiver::DefineOwnProperty(Isolate* isolate, Handle<JSReceiver> object, | 6057 bool JSReceiver::DefineOwnProperty(Isolate* isolate, Handle<JSReceiver> object, |
6124 Handle<Object> key, PropertyDescriptor* desc, | 6058 Handle<Object> key, PropertyDescriptor* desc, |
6125 ShouldThrow should_throw) { | 6059 ShouldThrow should_throw) { |
6126 if (object->IsJSArray()) { | 6060 if (object->IsJSArray()) { |
6127 return JSArray::DefineOwnProperty(isolate, Handle<JSArray>::cast(object), | 6061 return JSArray::DefineOwnProperty(isolate, Handle<JSArray>::cast(object), |
6128 key, desc, should_throw); | 6062 key, desc, should_throw); |
6129 } | 6063 } |
6064 if (object->IsJSProxy()) { | |
6065 return JSProxy::DefineOwnProperty(isolate, Handle<JSProxy>::cast(object), | |
6066 key, desc, should_throw); | |
6067 } | |
6130 // TODO(jkummerow): Support Modules (ES6 9.4.6.6) | 6068 // TODO(jkummerow): Support Modules (ES6 9.4.6.6) |
6131 // TODO(jkummerow): Support Proxies (ES6 9.5.6) | |
6132 if (!object->IsJSObject()) return true; | 6069 if (!object->IsJSObject()) return true; |
neis
2015/11/17 21:37:40
This condition will now always be false.
Jakob Kummerow
2015/11/18 14:35:50
Done.
| |
6133 | 6070 |
6134 // OrdinaryDefineOwnProperty, by virtue of calling | 6071 // OrdinaryDefineOwnProperty, by virtue of calling |
6135 // DefineOwnPropertyIgnoreAttributes, can handle arguments (ES6 9.4.4.2) | 6072 // DefineOwnPropertyIgnoreAttributes, can handle arguments (ES6 9.4.4.2) |
6136 // and IntegerIndexedExotics (ES6 9.4.5.3), with one exception: | 6073 // and IntegerIndexedExotics (ES6 9.4.5.3), with one exception: |
6137 // TODO(jkummerow): Setting an indexed accessor on a typed array should throw. | 6074 // TODO(jkummerow): Setting an indexed accessor on a typed array should throw. |
6138 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, | 6075 return OrdinaryDefineOwnProperty(isolate, Handle<JSObject>::cast(object), key, |
6139 desc, should_throw); | 6076 desc, should_throw); |
6140 } | 6077 } |
6141 | 6078 |
6142 | 6079 |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6703 success = actual_new_len == new_len; | 6640 success = actual_new_len == new_len; |
6704 if (!success && should_throw == THROW_ON_ERROR) { | 6641 if (!success && should_throw == THROW_ON_ERROR) { |
6705 isolate->Throw(*isolate->factory()->NewTypeError( | 6642 isolate->Throw(*isolate->factory()->NewTypeError( |
6706 MessageTemplate::kStrictDeleteProperty, | 6643 MessageTemplate::kStrictDeleteProperty, |
6707 isolate->factory()->NewNumberFromUint(actual_new_len - 1), a)); | 6644 isolate->factory()->NewNumberFromUint(actual_new_len - 1), a)); |
6708 } | 6645 } |
6709 return success; | 6646 return success; |
6710 } | 6647 } |
6711 | 6648 |
6712 | 6649 |
6650 // ES6 9.5.6 | |
6651 // static | |
6652 bool JSProxy::DefineOwnProperty(Isolate* isolate, Handle<JSProxy> object, | |
6653 Handle<Object> key, PropertyDescriptor* desc, | |
6654 ShouldThrow should_throw) { | |
6655 // 1. Assert: IsPropertyKey(P) is true. | |
6656 DCHECK(key->IsName() || key->IsNumber()); | |
6657 // 2. Let handler be the value of the [[ProxyHandler]] internal slot of O. | |
6658 Handle<Object> handler(object->handler(), isolate); | |
6659 // 3. If handler is null, throw a TypeError exception. | |
neis
2015/11/17 21:37:40
I would prefer using an IsRevoked function here.
Jakob Kummerow
2015/11/18 14:35:50
Yeah, well, we don't have that yet. I've added a T
| |
6660 if (handler->IsNull()) { | |
6661 isolate->Throw(*isolate->factory()->NewTypeError( | |
6662 MessageTemplate::kProxyHandlerNonObject)); | |
6663 return false; | |
6664 } | |
6665 // 4. Assert: Type(handler) is Object. | |
6666 DCHECK(handler->IsJSReceiver()); | |
6667 // If the handler is not null, the target can't be null either. | |
6668 DCHECK(object->target()->IsSpecObject()); | |
neis
2015/11/17 21:37:40
What is the relationship between IsSpecObject and
Jakob Kummerow
2015/11/18 14:35:50
They're identical. Consolidating the entire codeba
| |
6669 // 5. Let target be the value of the [[ProxyTarget]] internal slot of O. | |
6670 Handle<JSReceiver> target(JSReceiver::cast(object->target()), isolate); | |
6671 // 6. Let trap be ? GetMethod(handler, "defineProperty"). | |
6672 Handle<Object> trap; | |
6673 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
6674 isolate, trap, | |
6675 Object::GetMethod(Handle<JSReceiver>::cast(handler), | |
6676 isolate->factory()->defineProperty_string()), | |
6677 false); | |
6678 // 7. If trap is undefined, then: | |
6679 if (trap->IsUndefined()) { | |
6680 // 7a. Return target.[[DefineOwnProperty]](P, Desc). | |
6681 return JSReceiver::DefineOwnProperty(isolate, target, key, desc, | |
6682 should_throw); | |
6683 } | |
6684 // 8. Let descObj be FromPropertyDescriptor(Desc). | |
6685 Handle<Object> desc_obj = desc->ToObject(isolate); | |
6686 // 9. Let booleanTrapResult be | |
6687 // ToBoolean(? Call(trap, handler, «target, P, descObj»)). | |
6688 Handle<Name> property_name = | |
6689 key->IsName() | |
6690 ? Handle<Name>::cast(key) | |
6691 : Handle<Name>::cast(isolate->factory()->NumberToString(key)); | |
6692 Handle<Object> trap_result_obj; | |
6693 Handle<Object> args[] = {target, property_name, desc_obj}; | |
6694 ASSIGN_RETURN_ON_EXCEPTION_VALUE( | |
6695 isolate, trap_result_obj, | |
6696 Execution::Call(isolate, trap, handler, arraysize(args), args), false); | |
6697 // 10. If booleanTrapResult is false, return false. | |
6698 if (trap_result_obj->BooleanValue() == false) { | |
neis
2015/11/17 21:37:40
if (!...)
Jakob Kummerow
2015/11/18 14:35:50
Done. (I was intentionally staying close to the sp
| |
6699 if (should_throw == THROW_ON_ERROR) { | |
6700 // TODO(jkummerow): Better error message? | |
6701 isolate->Throw(*isolate->factory()->NewTypeError( | |
6702 MessageTemplate::kProxyHandlerReturned, handler, trap_result_obj, | |
6703 key)); | |
6704 } | |
6705 return false; | |
6706 } | |
6707 // 11. Let targetDesc be ? target.[[GetOwnProperty]](P). | |
6708 PropertyDescriptor target_desc; | |
6709 bool target_found = | |
6710 JSReceiver::GetOwnPropertyDescriptor(isolate, target, key, &target_desc); | |
6711 if (isolate->has_pending_exception()) return false; | |
6712 // 12. Let extensibleTarget be ? IsExtensible(target). | |
6713 Maybe<bool> maybe_extensible = JSReceiver::IsExtensible(target); | |
6714 if (maybe_extensible.IsNothing()) return false; | |
6715 bool extensible_target = maybe_extensible.FromJust(); | |
6716 // 13. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] | |
6717 // is false, then: | |
6718 // 13a. Let settingConfigFalse be true. | |
6719 // 14. Else let settingConfigFalse be false. | |
6720 bool setting_config_false = desc->has_configurable() && !desc->configurable(); | |
6721 // 15. If targetDesc is undefined, then | |
6722 if (!target_found) { | |
6723 // 15a. If extensibleTarget is false, throw a TypeError exception. | |
6724 if (!extensible_target) { | |
6725 isolate->Throw(*isolate->factory()->NewTypeError( | |
6726 MessageTemplate::kProxyTargetNotExtensible)); | |
6727 return false; | |
6728 } | |
6729 // 15b. If settingConfigFalse is true, throw a TypeError exception. | |
6730 if (setting_config_false) { | |
6731 // TODO(jkummerow): Better error message? | |
6732 isolate->Throw(*isolate->factory()->NewTypeError( | |
6733 MessageTemplate::kRedefineDisallowed, key)); | |
6734 return false; | |
6735 } | |
6736 } else { | |
6737 // 16. Else targetDesc is not undefined, | |
6738 // 16a. If IsCompatiblePropertyDescriptor(extensibleTarget, Desc, | |
6739 // targetDesc) is false, throw a TypeError exception. | |
6740 bool valid = IsCompatiblePropertyDescriptor( | |
6741 isolate, extensible_target, desc, &target_desc, property_name); | |
6742 if (!valid) { | |
6743 DCHECK(isolate->has_pending_exception()); | |
6744 return false; | |
6745 } | |
6746 // 16b. If settingConfigFalse is true and targetDesc.[[Configurable]] is | |
6747 // true, throw a TypeError exception. | |
6748 if (setting_config_false && target_desc.configurable()) { | |
6749 // TODO(jkummerow): Better error message? | |
6750 isolate->Throw(*isolate->factory()->NewTypeError( | |
6751 MessageTemplate::kRedefineDisallowed, key)); | |
6752 return false; | |
6753 } | |
6754 } | |
6755 // 17. Return true. | |
6756 return true; | |
6757 } | |
6758 | |
6759 | |
6713 // static | 6760 // static |
6714 bool JSReceiver::GetOwnPropertyDescriptor(Isolate* isolate, | 6761 bool JSReceiver::GetOwnPropertyDescriptor(Isolate* isolate, |
6715 Handle<JSReceiver> object, | 6762 Handle<JSReceiver> object, |
6716 Handle<Object> key, | 6763 Handle<Object> key, |
6717 PropertyDescriptor* desc) { | 6764 PropertyDescriptor* desc) { |
6718 bool success = false; | 6765 bool success = false; |
6719 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... | 6766 DCHECK(key->IsName() || key->IsNumber()); // |key| is a PropertyKey... |
6720 LookupIterator it = LookupIterator::PropertyOrElement( | 6767 LookupIterator it = LookupIterator::PropertyOrElement( |
6721 isolate, object, key, &success, LookupIterator::HIDDEN); | 6768 isolate, object, key, &success, LookupIterator::HIDDEN); |
6722 DCHECK(success); // ...so creating a LookupIterator can't fail. | 6769 DCHECK(success); // ...so creating a LookupIterator can't fail. |
(...skipping 11471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
18194 if (cell->value() != *new_value) { | 18241 if (cell->value() != *new_value) { |
18195 cell->set_value(*new_value); | 18242 cell->set_value(*new_value); |
18196 Isolate* isolate = cell->GetIsolate(); | 18243 Isolate* isolate = cell->GetIsolate(); |
18197 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 18244 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
18198 isolate, DependentCode::kPropertyCellChangedGroup); | 18245 isolate, DependentCode::kPropertyCellChangedGroup); |
18199 } | 18246 } |
18200 } | 18247 } |
18201 | 18248 |
18202 } // namespace internal | 18249 } // namespace internal |
18203 } // namespace v8 | 18250 } // namespace v8 |
OLD | NEW |