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 <iomanip> | 5 #include <iomanip> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/accessors.h" | 10 #include "src/accessors.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 if (js_object->map()->is_access_check_needed()) return false; | 120 if (js_object->map()->is_access_check_needed()) return false; |
121 auto isolate = js_object->GetIsolate(); | 121 auto isolate = js_object->GetIsolate(); |
122 // TODO(dcarney): this should just be read from the symbol registry so as not | 122 // TODO(dcarney): this should just be read from the symbol registry so as not |
123 // to be context dependent. | 123 // to be context dependent. |
124 auto key = isolate->promise_status(); | 124 auto key = isolate->promise_status(); |
125 // Shouldn't be possible to throw here. | 125 // Shouldn't be possible to throw here. |
126 return JSObject::HasRealNamedProperty(js_object, key).FromJust(); | 126 return JSObject::HasRealNamedProperty(js_object, key).FromJust(); |
127 } | 127 } |
128 | 128 |
129 | 129 |
130 MaybeHandle<Object> Object::GetProperty(LookupIterator* it) { | 130 MaybeHandle<Object> Object::GetProperty(LookupIterator* it, |
| 131 LanguageMode language_mode) { |
131 for (; it->IsFound(); it->Next()) { | 132 for (; it->IsFound(); it->Next()) { |
132 switch (it->state()) { | 133 switch (it->state()) { |
133 case LookupIterator::NOT_FOUND: | 134 case LookupIterator::NOT_FOUND: |
134 case LookupIterator::TRANSITION: | 135 case LookupIterator::TRANSITION: |
135 UNREACHABLE(); | 136 UNREACHABLE(); |
136 case LookupIterator::JSPROXY: | 137 case LookupIterator::JSPROXY: |
137 return JSProxy::GetPropertyWithHandler( | 138 return JSProxy::GetPropertyWithHandler( |
138 it->GetHolder<JSProxy>(), it->GetReceiver(), it->GetName()); | 139 it->GetHolder<JSProxy>(), it->GetReceiver(), it->GetName()); |
139 case LookupIterator::INTERCEPTOR: { | 140 case LookupIterator::INTERCEPTOR: { |
140 bool done; | 141 bool done; |
141 Handle<Object> result; | 142 Handle<Object> result; |
142 ASSIGN_RETURN_ON_EXCEPTION( | 143 ASSIGN_RETURN_ON_EXCEPTION( |
143 it->isolate(), result, | 144 it->isolate(), result, |
144 JSObject::GetPropertyWithInterceptor(it, &done), Object); | 145 JSObject::GetPropertyWithInterceptor(it, &done), Object); |
145 if (done) return result; | 146 if (done) return result; |
146 break; | 147 break; |
147 } | 148 } |
148 case LookupIterator::ACCESS_CHECK: | 149 case LookupIterator::ACCESS_CHECK: |
149 if (it->HasAccess()) break; | 150 if (it->HasAccess()) break; |
150 return JSObject::GetPropertyWithFailedAccessCheck(it); | 151 return JSObject::GetPropertyWithFailedAccessCheck(it, language_mode); |
151 case LookupIterator::ACCESSOR: | 152 case LookupIterator::ACCESSOR: |
152 return GetPropertyWithAccessor(it); | 153 return GetPropertyWithAccessor(it, language_mode); |
153 case LookupIterator::INTEGER_INDEXED_EXOTIC: | 154 case LookupIterator::INTEGER_INDEXED_EXOTIC: |
154 return it->factory()->undefined_value(); | 155 return ReadAbsentProperty(it, language_mode); |
155 case LookupIterator::DATA: | 156 case LookupIterator::DATA: |
156 return it->GetDataValue(); | 157 return it->GetDataValue(); |
157 } | 158 } |
158 } | 159 } |
159 return it->factory()->undefined_value(); | 160 return ReadAbsentProperty(it, language_mode); |
160 } | 161 } |
161 | 162 |
162 | 163 |
163 Handle<Object> JSReceiver::GetDataProperty(Handle<JSReceiver> object, | 164 Handle<Object> JSReceiver::GetDataProperty(Handle<JSReceiver> object, |
164 Handle<Name> name) { | 165 Handle<Name> name) { |
165 LookupIterator it(object, name, | 166 LookupIterator it(object, name, |
166 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); | 167 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); |
167 return GetDataProperty(&it); | 168 return GetDataProperty(&it); |
168 } | 169 } |
169 | 170 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 298 |
298 // TODO(rossberg): adjust once there is a story for symbols vs proxies. | 299 // TODO(rossberg): adjust once there is a story for symbols vs proxies. |
299 if (name->IsSymbol()) return isolate->factory()->undefined_value(); | 300 if (name->IsSymbol()) return isolate->factory()->undefined_value(); |
300 | 301 |
301 Handle<Object> args[] = { receiver, name }; | 302 Handle<Object> args[] = { receiver, name }; |
302 return CallTrap( | 303 return CallTrap( |
303 proxy, "get", isolate->derived_get_trap(), arraysize(args), args); | 304 proxy, "get", isolate->derived_get_trap(), arraysize(args), args); |
304 } | 305 } |
305 | 306 |
306 | 307 |
307 MaybeHandle<Object> Object::GetPropertyWithAccessor(LookupIterator* it) { | 308 MaybeHandle<Object> Object::GetPropertyWithAccessor( |
| 309 LookupIterator* it, LanguageMode language_mode) { |
308 Isolate* isolate = it->isolate(); | 310 Isolate* isolate = it->isolate(); |
309 Handle<Object> structure = it->GetAccessors(); | 311 Handle<Object> structure = it->GetAccessors(); |
310 Handle<Object> receiver = it->GetReceiver(); | 312 Handle<Object> receiver = it->GetReceiver(); |
311 | 313 |
312 // We should never get here to initialize a const with the hole value since a | 314 // We should never get here to initialize a const with the hole value since a |
313 // const declaration would conflict with the getter. | 315 // const declaration would conflict with the getter. |
314 DCHECK(!structure->IsForeign()); | 316 DCHECK(!structure->IsForeign()); |
315 | 317 |
316 // API style callbacks. | 318 // API style callbacks. |
317 if (structure->IsAccessorInfo()) { | 319 if (structure->IsAccessorInfo()) { |
(...skipping 11 matching lines...) Expand all Loading... |
329 v8::AccessorNameGetterCallback call_fun = | 331 v8::AccessorNameGetterCallback call_fun = |
330 v8::ToCData<v8::AccessorNameGetterCallback>(info->getter()); | 332 v8::ToCData<v8::AccessorNameGetterCallback>(info->getter()); |
331 if (call_fun == nullptr) return isolate->factory()->undefined_value(); | 333 if (call_fun == nullptr) return isolate->factory()->undefined_value(); |
332 | 334 |
333 LOG(isolate, ApiNamedPropertyAccess("load", *holder, *name)); | 335 LOG(isolate, ApiNamedPropertyAccess("load", *holder, *name)); |
334 PropertyCallbackArguments args(isolate, info->data(), *receiver, *holder); | 336 PropertyCallbackArguments args(isolate, info->data(), *receiver, *holder); |
335 v8::Handle<v8::Value> result = | 337 v8::Handle<v8::Value> result = |
336 args.Call(call_fun, v8::Utils::ToLocal(name)); | 338 args.Call(call_fun, v8::Utils::ToLocal(name)); |
337 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); | 339 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); |
338 if (result.IsEmpty()) { | 340 if (result.IsEmpty()) { |
339 return isolate->factory()->undefined_value(); | 341 return ReadAbsentProperty(isolate, receiver, name, language_mode); |
340 } | 342 } |
341 Handle<Object> return_value = v8::Utils::OpenHandle(*result); | 343 Handle<Object> return_value = v8::Utils::OpenHandle(*result); |
342 return_value->VerifyApiCallResultType(); | 344 return_value->VerifyApiCallResultType(); |
343 // Rebox handle before return. | 345 // Rebox handle before return. |
344 return handle(*return_value, isolate); | 346 return handle(*return_value, isolate); |
345 } | 347 } |
346 | 348 |
347 // Regular accessor. | 349 // Regular accessor. |
348 Handle<Object> getter(AccessorPair::cast(*structure)->getter(), isolate); | 350 Handle<Object> getter(AccessorPair::cast(*structure)->getter(), isolate); |
349 if (getter->IsSpecFunction()) { | 351 if (getter->IsSpecFunction()) { |
350 // TODO(rossberg): nicer would be to cast to some JSCallable here... | 352 // TODO(rossberg): nicer would be to cast to some JSCallable here... |
351 return Object::GetPropertyWithDefinedGetter( | 353 return Object::GetPropertyWithDefinedGetter( |
352 receiver, Handle<JSReceiver>::cast(getter)); | 354 receiver, Handle<JSReceiver>::cast(getter)); |
353 } | 355 } |
354 // Getter is not a function. | 356 // Getter is not a function. |
355 return isolate->factory()->undefined_value(); | 357 return ReadAbsentProperty(isolate, receiver, it->GetName(), language_mode); |
356 } | 358 } |
357 | 359 |
358 | 360 |
359 bool AccessorInfo::IsCompatibleReceiverMap(Isolate* isolate, | 361 bool AccessorInfo::IsCompatibleReceiverMap(Isolate* isolate, |
360 Handle<AccessorInfo> info, | 362 Handle<AccessorInfo> info, |
361 Handle<Map> map) { | 363 Handle<Map> map) { |
362 if (!info->HasExpectedReceiverType()) return true; | 364 if (!info->HasExpectedReceiverType()) return true; |
363 if (!map->IsJSObjectMap()) return false; | 365 if (!map->IsJSObjectMap()) return false; |
364 return FunctionTemplateInfo::cast(info->expected_receiver_type()) | 366 return FunctionTemplateInfo::cast(info->expected_receiver_type()) |
365 ->IsTemplateFor(*map); | 367 ->IsTemplateFor(*map); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 } | 483 } |
482 } else if (it->state() == LookupIterator::INTERCEPTOR) { | 484 } else if (it->state() == LookupIterator::INTERCEPTOR) { |
483 if (it->GetInterceptor()->all_can_read()) return true; | 485 if (it->GetInterceptor()->all_can_read()) return true; |
484 } | 486 } |
485 } | 487 } |
486 return false; | 488 return false; |
487 } | 489 } |
488 | 490 |
489 | 491 |
490 MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck( | 492 MaybeHandle<Object> JSObject::GetPropertyWithFailedAccessCheck( |
491 LookupIterator* it) { | 493 LookupIterator* it, LanguageMode language_mode) { |
492 Handle<JSObject> checked = it->GetHolder<JSObject>(); | 494 Handle<JSObject> checked = it->GetHolder<JSObject>(); |
493 while (FindAllCanReadHolder(it)) { | 495 while (FindAllCanReadHolder(it)) { |
494 if (it->state() == LookupIterator::ACCESSOR) { | 496 if (it->state() == LookupIterator::ACCESSOR) { |
495 return GetPropertyWithAccessor(it); | 497 return GetPropertyWithAccessor(it, language_mode); |
496 } | 498 } |
497 DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state()); | 499 DCHECK_EQ(LookupIterator::INTERCEPTOR, it->state()); |
498 bool done; | 500 bool done; |
499 Handle<Object> result; | 501 Handle<Object> result; |
500 ASSIGN_RETURN_ON_EXCEPTION(it->isolate(), result, | 502 ASSIGN_RETURN_ON_EXCEPTION(it->isolate(), result, |
501 GetPropertyWithInterceptor(it, &done), Object); | 503 GetPropertyWithInterceptor(it, &done), Object); |
502 if (done) return result; | 504 if (done) return result; |
503 } | 505 } |
504 it->isolate()->ReportFailedAccessCheck(checked); | 506 it->isolate()->ReportFailedAccessCheck(checked); |
505 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(it->isolate(), Object); | 507 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(it->isolate(), Object); |
(...skipping 2709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3215 case LookupIterator::TRANSITION: | 3217 case LookupIterator::TRANSITION: |
3216 UNREACHABLE(); | 3218 UNREACHABLE(); |
3217 } | 3219 } |
3218 } | 3220 } |
3219 | 3221 |
3220 return JSObject::AddDataProperty(&own_lookup, value, NONE, language_mode, | 3222 return JSObject::AddDataProperty(&own_lookup, value, NONE, language_mode, |
3221 store_mode); | 3223 store_mode); |
3222 } | 3224 } |
3223 | 3225 |
3224 | 3226 |
| 3227 MaybeHandle<Object> Object::ReadAbsentProperty(LookupIterator* it, |
| 3228 LanguageMode language_mode) { |
| 3229 return ReadAbsentProperty(it->isolate(), it->GetReceiver(), it->GetName(), |
| 3230 language_mode); |
| 3231 } |
| 3232 |
| 3233 MaybeHandle<Object> Object::ReadAbsentProperty(Isolate* isolate, |
| 3234 Handle<Object> receiver, |
| 3235 Handle<Object> name, |
| 3236 LanguageMode language_mode) { |
| 3237 if (is_strong(language_mode)) { |
| 3238 THROW_NEW_ERROR( |
| 3239 isolate, |
| 3240 NewTypeError(MessageTemplate::kStrongPropertyAccess, name, receiver), |
| 3241 Object); |
| 3242 } |
| 3243 return isolate->factory()->undefined_value(); |
| 3244 } |
| 3245 |
| 3246 |
3225 MaybeHandle<Object> Object::WriteToReadOnlyProperty( | 3247 MaybeHandle<Object> Object::WriteToReadOnlyProperty( |
3226 LookupIterator* it, Handle<Object> value, LanguageMode language_mode) { | 3248 LookupIterator* it, Handle<Object> value, LanguageMode language_mode) { |
3227 return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), | 3249 return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), |
3228 it->GetName(), value, language_mode); | 3250 it->GetName(), value, language_mode); |
3229 } | 3251 } |
3230 | 3252 |
3231 | 3253 |
3232 MaybeHandle<Object> Object::WriteToReadOnlyProperty( | 3254 MaybeHandle<Object> Object::WriteToReadOnlyProperty( |
3233 Isolate* isolate, Handle<Object> receiver, Handle<Object> name, | 3255 Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
3234 Handle<Object> value, LanguageMode language_mode) { | 3256 Handle<Object> value, LanguageMode language_mode) { |
(...skipping 13427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16662 Handle<Object> new_value) { | 16684 Handle<Object> new_value) { |
16663 if (cell->value() != *new_value) { | 16685 if (cell->value() != *new_value) { |
16664 cell->set_value(*new_value); | 16686 cell->set_value(*new_value); |
16665 Isolate* isolate = cell->GetIsolate(); | 16687 Isolate* isolate = cell->GetIsolate(); |
16666 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16688 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
16667 isolate, DependentCode::kPropertyCellChangedGroup); | 16689 isolate, DependentCode::kPropertyCellChangedGroup); |
16668 } | 16690 } |
16669 } | 16691 } |
16670 } // namespace internal | 16692 } // namespace internal |
16671 } // namespace v8 | 16693 } // namespace v8 |
OLD | NEW |