| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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-natives.h" | 5 #include "src/api-natives.h" |
| 6 | 6 |
| 7 #include "src/api.h" | 7 #include "src/api.h" |
| 8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
| 9 #include "src/lookup.h" | 9 #include "src/lookup.h" |
| 10 #include "src/messages.h" | 10 #include "src/messages.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 DCHECK((unchecked_attributes->value() & | 73 DCHECK((unchecked_attributes->value() & |
| 74 ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); | 74 ~(READ_ONLY | DONT_ENUM | DONT_DELETE)) == 0); |
| 75 // Compute attributes. | 75 // Compute attributes. |
| 76 PropertyAttributes attributes = | 76 PropertyAttributes attributes = |
| 77 static_cast<PropertyAttributes>(unchecked_attributes->value()); | 77 static_cast<PropertyAttributes>(unchecked_attributes->value()); |
| 78 | 78 |
| 79 Handle<Object> value; | 79 Handle<Object> value; |
| 80 ASSIGN_RETURN_ON_EXCEPTION(isolate, value, | 80 ASSIGN_RETURN_ON_EXCEPTION(isolate, value, |
| 81 Instantiate(isolate, prop_data, key), Object); | 81 Instantiate(isolate, prop_data, key), Object); |
| 82 | 82 |
| 83 uint32_t index = 0; |
| 84 LookupIterator::Configuration c = LookupIterator::OWN_SKIP_INTERCEPTOR; |
| 85 LookupIterator it = key->AsArrayIndex(&index) |
| 86 ? LookupIterator(isolate, object, index, c) |
| 87 : LookupIterator(object, key, c); |
| 88 |
| 83 #ifdef DEBUG | 89 #ifdef DEBUG |
| 84 bool duplicate; | 90 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 85 if (key->IsName()) { | 91 DCHECK(maybe.IsJust()); |
| 86 LookupIterator it(object, Handle<Name>::cast(key), | 92 if (it.IsFound()) { |
| 87 LookupIterator::OWN_SKIP_INTERCEPTOR); | |
| 88 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | |
| 89 DCHECK(maybe.IsJust()); | |
| 90 duplicate = it.IsFound(); | |
| 91 } else { | |
| 92 uint32_t index = 0; | |
| 93 key->ToArrayIndex(&index); | |
| 94 Maybe<bool> maybe = JSReceiver::HasOwnElement(object, index); | |
| 95 if (!maybe.IsJust()) return MaybeHandle<Object>(); | |
| 96 duplicate = maybe.FromJust(); | |
| 97 } | |
| 98 if (duplicate) { | |
| 99 THROW_NEW_ERROR( | 93 THROW_NEW_ERROR( |
| 100 isolate, NewTypeError(MessageTemplate::kDuplicateTemplateProperty, key), | 94 isolate, NewTypeError(MessageTemplate::kDuplicateTemplateProperty, key), |
| 101 Object); | 95 Object); |
| 102 } | 96 } |
| 103 #endif | 97 #endif |
| 104 | 98 |
| 105 RETURN_ON_EXCEPTION( | 99 return Object::AddDataProperty(&it, value, attributes, STRICT, |
| 106 isolate, Runtime::DefineObjectProperty(object, key, value, attributes), | 100 Object::CERTAINLY_NOT_STORE_FROM_KEYED); |
| 107 Object); | |
| 108 return object; | |
| 109 } | 101 } |
| 110 | 102 |
| 111 | 103 |
| 112 void DisableAccessChecks(Isolate* isolate, Handle<JSObject> object) { | 104 void DisableAccessChecks(Isolate* isolate, Handle<JSObject> object) { |
| 113 Handle<Map> old_map(object->map()); | 105 Handle<Map> old_map(object->map()); |
| 114 // Copy map so it won't interfere constructor's initial map. | 106 // Copy map so it won't interfere constructor's initial map. |
| 115 Handle<Map> new_map = Map::Copy(old_map, "DisableAccessChecks"); | 107 Handle<Map> new_map = Map::Copy(old_map, "DisableAccessChecks"); |
| 116 new_map->set_is_access_check_needed(false); | 108 new_map->set_is_access_check_needed(false); |
| 117 JSObject::MigrateToMap(Handle<JSObject>::cast(object), new_map); | 109 JSObject::MigrateToMap(Handle<JSObject>::cast(object), new_map); |
| 118 } | 110 } |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); | 571 Handle<AccessorInfo> accessor(AccessorInfo::cast(array->get(i))); |
| 580 JSObject::SetAccessor(result, accessor).Assert(); | 572 JSObject::SetAccessor(result, accessor).Assert(); |
| 581 } | 573 } |
| 582 | 574 |
| 583 DCHECK(result->shared()->IsApiFunction()); | 575 DCHECK(result->shared()->IsApiFunction()); |
| 584 return result; | 576 return result; |
| 585 } | 577 } |
| 586 | 578 |
| 587 } // namespace internal | 579 } // namespace internal |
| 588 } // namespace v8 | 580 } // namespace v8 |
| OLD | NEW |