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); |
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { |
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, SLOPPY); |
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 2701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3207 case LookupIterator::TRANSITION: | 3209 case LookupIterator::TRANSITION: |
3208 UNREACHABLE(); | 3210 UNREACHABLE(); |
3209 } | 3211 } |
3210 } | 3212 } |
3211 | 3213 |
3212 return JSObject::AddDataProperty(&own_lookup, value, NONE, language_mode, | 3214 return JSObject::AddDataProperty(&own_lookup, value, NONE, language_mode, |
3213 store_mode); | 3215 store_mode); |
3214 } | 3216 } |
3215 | 3217 |
3216 | 3218 |
| 3219 MaybeHandle<Object> Object::ReadAbsentProperty(LookupIterator* it, |
| 3220 LanguageMode language_mode) { |
| 3221 if (is_strong(language_mode)) { |
| 3222 THROW_NEW_ERROR(it->isolate(), |
| 3223 NewTypeError(MessageTemplate::kStrongPropertyAccess, |
| 3224 it->GetName(), it->GetReceiver()), |
| 3225 Object); |
| 3226 } |
| 3227 return it->isolate()->factory()->undefined_value(); |
| 3228 } |
| 3229 |
| 3230 MaybeHandle<Object> Object::ReadAbsentProperty(Isolate* isolate, |
| 3231 Handle<Object> receiver, |
| 3232 Handle<Object> name, |
| 3233 LanguageMode language_mode) { |
| 3234 if (is_strong(language_mode)) { |
| 3235 THROW_NEW_ERROR( |
| 3236 isolate, |
| 3237 NewTypeError(MessageTemplate::kStrongPropertyAccess, name, receiver), |
| 3238 Object); |
| 3239 } |
| 3240 return isolate->factory()->undefined_value(); |
| 3241 } |
| 3242 |
| 3243 |
3217 MaybeHandle<Object> Object::WriteToReadOnlyProperty( | 3244 MaybeHandle<Object> Object::WriteToReadOnlyProperty( |
3218 LookupIterator* it, Handle<Object> value, LanguageMode language_mode) { | 3245 LookupIterator* it, Handle<Object> value, LanguageMode language_mode) { |
3219 return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), | 3246 return WriteToReadOnlyProperty(it->isolate(), it->GetReceiver(), |
3220 it->GetName(), value, language_mode); | 3247 it->GetName(), value, language_mode); |
3221 } | 3248 } |
3222 | 3249 |
3223 | 3250 |
3224 MaybeHandle<Object> Object::WriteToReadOnlyProperty( | 3251 MaybeHandle<Object> Object::WriteToReadOnlyProperty( |
3225 Isolate* isolate, Handle<Object> receiver, Handle<Object> name, | 3252 Isolate* isolate, Handle<Object> receiver, Handle<Object> name, |
3226 Handle<Object> value, LanguageMode language_mode) { | 3253 Handle<Object> value, LanguageMode language_mode) { |
(...skipping 12923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16150 Handle<Object> new_value) { | 16177 Handle<Object> new_value) { |
16151 if (cell->value() != *new_value) { | 16178 if (cell->value() != *new_value) { |
16152 cell->set_value(*new_value); | 16179 cell->set_value(*new_value); |
16153 Isolate* isolate = cell->GetIsolate(); | 16180 Isolate* isolate = cell->GetIsolate(); |
16154 cell->dependent_code()->DeoptimizeDependentCodeGroup( | 16181 cell->dependent_code()->DeoptimizeDependentCodeGroup( |
16155 isolate, DependentCode::kPropertyCellChangedGroup); | 16182 isolate, DependentCode::kPropertyCellChangedGroup); |
16156 } | 16183 } |
16157 } | 16184 } |
16158 } // namespace internal | 16185 } // namespace internal |
16159 } // namespace v8 | 16186 } // namespace v8 |
OLD | NEW |