| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
| 6 | 6 |
| 7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
| 8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
| 9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
| 10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 }; | 198 }; |
| 199 | 199 |
| 200 | 200 |
| 201 MUST_USE_RESULT static MaybeHandle<Object> GetOwnProperty(Isolate* isolate, | 201 MUST_USE_RESULT static MaybeHandle<Object> GetOwnProperty(Isolate* isolate, |
| 202 Handle<JSObject> obj, | 202 Handle<JSObject> obj, |
| 203 Handle<Name> name) { | 203 Handle<Name> name) { |
| 204 Heap* heap = isolate->heap(); | 204 Heap* heap = isolate->heap(); |
| 205 Factory* factory = isolate->factory(); | 205 Factory* factory = isolate->factory(); |
| 206 | 206 |
| 207 // Get attributes. | 207 // Get attributes. |
| 208 LookupIterator it = LookupIterator::PropertyOrElement(isolate, obj, name, | 208 LookupIterator it = LookupIterator::PropertyOrElement(isolate, obj, name, obj, |
| 209 LookupIterator::HIDDEN); | 209 LookupIterator::HIDDEN); |
| 210 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); | 210 Maybe<PropertyAttributes> maybe = JSObject::GetPropertyAttributes(&it); |
| 211 | 211 |
| 212 if (!maybe.IsJust()) return MaybeHandle<Object>(); | 212 if (!maybe.IsJust()) return MaybeHandle<Object>(); |
| 213 PropertyAttributes attrs = maybe.FromJust(); | 213 PropertyAttributes attrs = maybe.FromJust(); |
| 214 if (attrs == ABSENT) return factory->undefined_value(); | 214 if (attrs == ABSENT) return factory->undefined_value(); |
| 215 | 215 |
| 216 DCHECK(!isolate->has_pending_exception()); | 216 DCHECK(!isolate->has_pending_exception()); |
| 217 Handle<FixedArray> elms = factory->NewFixedArray(DESCRIPTOR_SIZE); | 217 Handle<FixedArray> elms = factory->NewFixedArray(DESCRIPTOR_SIZE); |
| 218 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); | 218 elms->set(ENUMERABLE_INDEX, heap->ToBoolean((attrs & DONT_ENUM) == 0)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // Go up context chain to the script context. | 286 // Go up context chain to the script context. |
| 287 Handle<Context> script_context(isolate->context()->script_context(), isolate); | 287 Handle<Context> script_context(isolate->context()->script_context(), isolate); |
| 288 DCHECK(script_context->IsScriptContext()); | 288 DCHECK(script_context->IsScriptContext()); |
| 289 DCHECK(script_context->get(slot)->IsPropertyCell()); | 289 DCHECK(script_context->get(slot)->IsPropertyCell()); |
| 290 | 290 |
| 291 // Lookup the named property on the global object. | 291 // Lookup the named property on the global object. |
| 292 Handle<ScopeInfo> scope_info(script_context->scope_info(), isolate); | 292 Handle<ScopeInfo> scope_info(script_context->scope_info(), isolate); |
| 293 Handle<Name> name(scope_info->ContextSlotName(slot), isolate); | 293 Handle<Name> name(scope_info->ContextSlotName(slot), isolate); |
| 294 Handle<JSGlobalObject> global_object(script_context->global_object(), | 294 Handle<JSGlobalObject> global_object(script_context->global_object(), |
| 295 isolate); | 295 isolate); |
| 296 LookupIterator it(global_object, name, LookupIterator::HIDDEN); | 296 LookupIterator it(global_object, name, global_object, LookupIterator::HIDDEN); |
| 297 | 297 |
| 298 // Switch to fast mode only if there is a data property and it's not on | 298 // Switch to fast mode only if there is a data property and it's not on |
| 299 // a hidden prototype. | 299 // a hidden prototype. |
| 300 if (it.state() == LookupIterator::DATA && | 300 if (it.state() == LookupIterator::DATA && |
| 301 it.GetHolder<Object>().is_identical_to(global_object)) { | 301 it.GetHolder<Object>().is_identical_to(global_object)) { |
| 302 // Now update the cell in the script context. | 302 // Now update the cell in the script context. |
| 303 Handle<PropertyCell> cell = it.GetPropertyCell(); | 303 Handle<PropertyCell> cell = it.GetPropertyCell(); |
| 304 script_context->set(slot, *cell); | 304 script_context->set(slot, *cell); |
| 305 } else { | 305 } else { |
| 306 // This is not a fast case, so keep this access in a slow mode. | 306 // This is not a fast case, so keep this access in a slow mode. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 321 // Go up context chain to the script context. | 321 // Go up context chain to the script context. |
| 322 Handle<Context> script_context(isolate->context()->script_context(), isolate); | 322 Handle<Context> script_context(isolate->context()->script_context(), isolate); |
| 323 DCHECK(script_context->IsScriptContext()); | 323 DCHECK(script_context->IsScriptContext()); |
| 324 DCHECK(script_context->get(slot)->IsPropertyCell()); | 324 DCHECK(script_context->get(slot)->IsPropertyCell()); |
| 325 | 325 |
| 326 // Lookup the named property on the global object. | 326 // Lookup the named property on the global object. |
| 327 Handle<ScopeInfo> scope_info(script_context->scope_info(), isolate); | 327 Handle<ScopeInfo> scope_info(script_context->scope_info(), isolate); |
| 328 Handle<Name> name(scope_info->ContextSlotName(slot), isolate); | 328 Handle<Name> name(scope_info->ContextSlotName(slot), isolate); |
| 329 Handle<JSGlobalObject> global_object(script_context->global_object(), | 329 Handle<JSGlobalObject> global_object(script_context->global_object(), |
| 330 isolate); | 330 isolate); |
| 331 LookupIterator it(global_object, name, LookupIterator::HIDDEN); | 331 LookupIterator it(global_object, name, global_object, LookupIterator::HIDDEN); |
| 332 | 332 |
| 333 // Switch to fast mode only if there is a data property and it's not on | 333 // Switch to fast mode only if there is a data property and it's not on |
| 334 // a hidden prototype. | 334 // a hidden prototype. |
| 335 if (it.state() == LookupIterator::DATA && | 335 if (it.state() == LookupIterator::DATA && |
| 336 it.GetHolder<Object>().is_identical_to(global_object)) { | 336 it.GetHolder<Object>().is_identical_to(global_object)) { |
| 337 // Now update cell in the script context. | 337 // Now update cell in the script context. |
| 338 Handle<PropertyCell> cell = it.GetPropertyCell(); | 338 Handle<PropertyCell> cell = it.GetPropertyCell(); |
| 339 script_context->set(slot, *cell); | 339 script_context->set(slot, *cell); |
| 340 } else { | 340 } else { |
| 341 // This is not a fast case, so keep this access in a slow mode. | 341 // This is not a fast case, so keep this access in a slow mode. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 RUNTIME_ASSERT(args.length() == 4); | 406 RUNTIME_ASSERT(args.length() == 4); |
| 407 | 407 |
| 408 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 408 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 409 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 409 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 410 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 410 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 411 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 411 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
| 412 | 412 |
| 413 #ifdef DEBUG | 413 #ifdef DEBUG |
| 414 uint32_t index = 0; | 414 uint32_t index = 0; |
| 415 DCHECK(!name->ToArrayIndex(&index)); | 415 DCHECK(!name->ToArrayIndex(&index)); |
| 416 LookupIterator it(object, name, LookupIterator::OWN_SKIP_INTERCEPTOR); | 416 LookupIterator it(object, name, object, LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 417 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 417 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 418 if (!maybe.IsJust()) return isolate->heap()->exception(); | 418 if (!maybe.IsJust()) return isolate->heap()->exception(); |
| 419 RUNTIME_ASSERT(!it.IsFound()); | 419 RUNTIME_ASSERT(!it.IsFound()); |
| 420 #endif | 420 #endif |
| 421 | 421 |
| 422 Handle<Object> result; | 422 Handle<Object> result; |
| 423 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 423 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 424 isolate, result, | 424 isolate, result, |
| 425 JSObject::SetOwnPropertyIgnoreAttributes(object, name, value, attrs)); | 425 JSObject::SetOwnPropertyIgnoreAttributes(object, name, value, attrs)); |
| 426 return *result; | 426 return *result; |
| 427 } | 427 } |
| 428 | 428 |
| 429 | 429 |
| 430 // Adds an element to an array. | 430 // Adds an element to an array. |
| 431 // This is used to create an indexed data property into an array. | 431 // This is used to create an indexed data property into an array. |
| 432 RUNTIME_FUNCTION(Runtime_AddElement) { | 432 RUNTIME_FUNCTION(Runtime_AddElement) { |
| 433 HandleScope scope(isolate); | 433 HandleScope scope(isolate); |
| 434 RUNTIME_ASSERT(args.length() == 3); | 434 RUNTIME_ASSERT(args.length() == 3); |
| 435 | 435 |
| 436 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 436 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 437 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); | 437 CONVERT_ARG_HANDLE_CHECKED(Object, key, 1); |
| 438 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 438 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 439 | 439 |
| 440 uint32_t index = 0; | 440 uint32_t index = 0; |
| 441 CHECK(key->ToArrayIndex(&index)); | 441 CHECK(key->ToArrayIndex(&index)); |
| 442 | 442 |
| 443 #ifdef DEBUG | 443 #ifdef DEBUG |
| 444 LookupIterator it(isolate, object, index, | 444 LookupIterator it(isolate, object, index, object, |
| 445 LookupIterator::OWN_SKIP_INTERCEPTOR); | 445 LookupIterator::OWN_SKIP_INTERCEPTOR); |
| 446 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 446 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 447 if (!maybe.IsJust()) return isolate->heap()->exception(); | 447 if (!maybe.IsJust()) return isolate->heap()->exception(); |
| 448 RUNTIME_ASSERT(!it.IsFound()); | 448 RUNTIME_ASSERT(!it.IsFound()); |
| 449 | 449 |
| 450 if (object->IsJSArray()) { | 450 if (object->IsJSArray()) { |
| 451 Handle<JSArray> array = Handle<JSArray>::cast(object); | 451 Handle<JSArray> array = Handle<JSArray>::cast(object); |
| 452 RUNTIME_ASSERT(!JSArray::WouldChangeReadOnlyLength(array, index)); | 452 RUNTIME_ASSERT(!JSArray::WouldChangeReadOnlyLength(array, index)); |
| 453 } | 453 } |
| 454 #endif | 454 #endif |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 // Step 12 - update an existing data property with a data or generic | 754 // Step 12 - update an existing data property with a data or generic |
| 755 // descriptor. | 755 // descriptor. |
| 756 RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) { | 756 RUNTIME_FUNCTION(Runtime_DefineDataPropertyUnchecked) { |
| 757 HandleScope scope(isolate); | 757 HandleScope scope(isolate); |
| 758 DCHECK(args.length() == 4); | 758 DCHECK(args.length() == 4); |
| 759 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 759 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 760 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 760 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 761 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 761 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 762 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 762 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
| 763 | 763 |
| 764 LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name, | 764 LookupIterator it = LookupIterator::PropertyOrElement( |
| 765 LookupIterator::OWN); | 765 isolate, object, name, object, LookupIterator::OWN); |
| 766 if (it.state() == LookupIterator::ACCESS_CHECK && !it.HasAccess()) { | 766 if (it.state() == LookupIterator::ACCESS_CHECK && !it.HasAccess()) { |
| 767 return isolate->heap()->undefined_value(); | 767 return isolate->heap()->undefined_value(); |
| 768 } | 768 } |
| 769 | 769 |
| 770 Handle<Object> result; | 770 Handle<Object> result; |
| 771 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 771 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 772 isolate, result, JSObject::DefineOwnPropertyIgnoreAttributes( | 772 isolate, result, JSObject::DefineOwnPropertyIgnoreAttributes( |
| 773 &it, value, attrs, JSObject::DONT_FORCE_FIELD)); | 773 &it, value, attrs, JSObject::DONT_FORCE_FIELD)); |
| 774 | 774 |
| 775 return *result; | 775 return *result; |
| 776 } | 776 } |
| 777 | 777 |
| 778 RUNTIME_FUNCTION(Runtime_DefineDataPropertyInLiteral) { | 778 RUNTIME_FUNCTION(Runtime_DefineDataPropertyInLiteral) { |
| 779 HandleScope scope(isolate); | 779 HandleScope scope(isolate); |
| 780 DCHECK(args.length() == 5); | 780 DCHECK(args.length() == 5); |
| 781 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); | 781 CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); |
| 782 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); | 782 CONVERT_ARG_HANDLE_CHECKED(Name, name, 1); |
| 783 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); | 783 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); |
| 784 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); | 784 CONVERT_PROPERTY_ATTRIBUTES_CHECKED(attrs, 3); |
| 785 CONVERT_SMI_ARG_CHECKED(set_function_name, 4); | 785 CONVERT_SMI_ARG_CHECKED(set_function_name, 4); |
| 786 | 786 |
| 787 if (FLAG_harmony_function_name && set_function_name) { | 787 if (FLAG_harmony_function_name && set_function_name) { |
| 788 DCHECK(value->IsJSFunction()); | 788 DCHECK(value->IsJSFunction()); |
| 789 JSFunction::SetName(Handle<JSFunction>::cast(value), name, | 789 JSFunction::SetName(Handle<JSFunction>::cast(value), name, |
| 790 isolate->factory()->empty_string()); | 790 isolate->factory()->empty_string()); |
| 791 } | 791 } |
| 792 | 792 |
| 793 LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name, | 793 LookupIterator it = LookupIterator::PropertyOrElement( |
| 794 LookupIterator::OWN); | 794 isolate, object, name, object, LookupIterator::OWN); |
| 795 // Cannot fail since this should only be called when | 795 // Cannot fail since this should only be called when |
| 796 // creating an object literal. | 796 // creating an object literal. |
| 797 CHECK(JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attrs, | 797 CHECK(JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, attrs, |
| 798 Object::DONT_THROW) | 798 Object::DONT_THROW) |
| 799 .IsJust()); | 799 .IsJust()); |
| 800 return *object; | 800 return *object; |
| 801 } | 801 } |
| 802 | 802 |
| 803 // Return property without being observable by accessors or interceptors. | 803 // Return property without being observable by accessors or interceptors. |
| 804 RUNTIME_FUNCTION(Runtime_GetDataProperty) { | 804 RUNTIME_FUNCTION(Runtime_GetDataProperty) { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 DCHECK(args.length() == 2); | 1122 DCHECK(args.length() == 2); |
| 1123 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); | 1123 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); |
| 1124 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); | 1124 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); |
| 1125 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1125 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
| 1126 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); | 1126 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); |
| 1127 return *o; | 1127 return *o; |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 } // namespace internal | 1130 } // namespace internal |
| 1131 } // namespace v8 | 1131 } // namespace v8 |
| OLD | NEW |