| 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
| 9 #include "src/frames-inl.h" | 9 #include "src/frames-inl.h" |
| 10 #include "src/runtime/runtime-utils.h" | 10 #include "src/runtime/runtime-utils.h" |
| 11 #include "src/scopeinfo.h" | 11 #include "src/scopeinfo.h" |
| 12 #include "src/scopes.h" | 12 #include "src/scopes.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) { | 17 static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) { |
| 18 HandleScope scope(isolate); | 18 HandleScope scope(isolate); |
| 19 Handle<Object> args[1] = {name}; | 19 Handle<Object> args[1] = {name}; |
| 20 THROW_NEW_ERROR_RETURN_FAILURE( | 20 THROW_NEW_ERROR_RETURN_FAILURE( |
| 21 isolate, NewTypeError("var_redeclaration", HandleVector(args, 1))); | 21 isolate, NewTypeError("var_redeclaration", HandleVector(args, 1))); |
| 22 } | 22 } |
| 23 | 23 |
| 24 | 24 |
| 25 // May throw a RedeclarationError. | 25 // May throw a RedeclarationError. |
| 26 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global, | 26 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global, |
| 27 Handle<String> name, Handle<Object> value, | 27 Handle<String> name, Handle<Object> value, |
| 28 PropertyAttributes attr, bool is_var, | 28 PropertyAttributes attr, bool is_var, |
| 29 bool is_const, bool is_function) { | 29 bool is_const, bool is_function) { |
| 30 Handle<GlobalContextTable> global_contexts( | 30 Handle<ScriptContextTable> script_contexts( |
| 31 global->native_context()->global_context_table()); | 31 global->native_context()->script_context_table()); |
| 32 GlobalContextTable::LookupResult lookup; | 32 ScriptContextTable::LookupResult lookup; |
| 33 if (GlobalContextTable::Lookup(global_contexts, name, &lookup) && | 33 if (ScriptContextTable::Lookup(script_contexts, name, &lookup) && |
| 34 IsLexicalVariableMode(lookup.mode)) { | 34 IsLexicalVariableMode(lookup.mode)) { |
| 35 return ThrowRedeclarationError(isolate, name); | 35 return ThrowRedeclarationError(isolate, name); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Do the lookup own properties only, see ES5 erratum. | 38 // Do the lookup own properties only, see ES5 erratum. |
| 39 LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 39 LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); |
| 40 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 40 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 41 if (!maybe.has_value) return isolate->heap()->exception(); | 41 if (!maybe.has_value) return isolate->heap()->exception(); |
| 42 | 42 |
| 43 if (it.IsFound()) { | 43 if (it.IsFound()) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 global, name, value, attr)); | 190 global, name, value, attr)); |
| 191 | 191 |
| 192 return *value; | 192 return *value; |
| 193 } | 193 } |
| 194 | 194 |
| 195 | 195 |
| 196 RUNTIME_FUNCTION(Runtime_DeclareLookupSlot) { | 196 RUNTIME_FUNCTION(Runtime_DeclareLookupSlot) { |
| 197 HandleScope scope(isolate); | 197 HandleScope scope(isolate); |
| 198 DCHECK(args.length() == 4); | 198 DCHECK(args.length() == 4); |
| 199 | 199 |
| 200 // Declarations are always made in a function, native, or global context. In | 200 // Declarations are always made in a function, eval or script context. In |
| 201 // the case of eval code, the context passed is the context of the caller, | 201 // the case of eval code, the context passed is the context of the caller, |
| 202 // which may be some nested context and not the declaration context. | 202 // which may be some nested context and not the declaration context. |
| 203 CONVERT_ARG_HANDLE_CHECKED(Context, context_arg, 0); | 203 CONVERT_ARG_HANDLE_CHECKED(Context, context_arg, 0); |
| 204 Handle<Context> context(context_arg->declaration_context()); | 204 Handle<Context> context(context_arg->declaration_context()); |
| 205 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); | 205 CONVERT_ARG_HANDLE_CHECKED(String, name, 1); |
| 206 CONVERT_SMI_ARG_CHECKED(attr_arg, 2); | 206 CONVERT_SMI_ARG_CHECKED(attr_arg, 2); |
| 207 PropertyAttributes attr = static_cast<PropertyAttributes>(attr_arg); | 207 PropertyAttributes attr = static_cast<PropertyAttributes>(attr_arg); |
| 208 RUNTIME_ASSERT(attr == READ_ONLY || attr == NONE); | 208 RUNTIME_ASSERT(attr == READ_ONLY || attr == NONE); |
| 209 CONVERT_ARG_HANDLE_CHECKED(Object, initial_value, 3); | 209 CONVERT_ARG_HANDLE_CHECKED(Object, initial_value, 3); |
| 210 | 210 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 510 |
| 511 // The caller ensures that we pretenure closures that are assigned | 511 // The caller ensures that we pretenure closures that are assigned |
| 512 // directly to properties. | 512 // directly to properties. |
| 513 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; | 513 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; |
| 514 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, | 514 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, |
| 515 pretenure_flag); | 515 pretenure_flag); |
| 516 } | 516 } |
| 517 | 517 |
| 518 static Object* FindNameClash(Handle<ScopeInfo> scope_info, | 518 static Object* FindNameClash(Handle<ScopeInfo> scope_info, |
| 519 Handle<GlobalObject> global_object, | 519 Handle<GlobalObject> global_object, |
| 520 Handle<GlobalContextTable> global_context) { | 520 Handle<ScriptContextTable> script_context) { |
| 521 Isolate* isolate = scope_info->GetIsolate(); | 521 Isolate* isolate = scope_info->GetIsolate(); |
| 522 for (int var = 0; var < scope_info->ContextLocalCount(); var++) { | 522 for (int var = 0; var < scope_info->ContextLocalCount(); var++) { |
| 523 Handle<String> name(scope_info->ContextLocalName(var)); | 523 Handle<String> name(scope_info->ContextLocalName(var)); |
| 524 VariableMode mode = scope_info->ContextLocalMode(var); | 524 VariableMode mode = scope_info->ContextLocalMode(var); |
| 525 GlobalContextTable::LookupResult lookup; | 525 ScriptContextTable::LookupResult lookup; |
| 526 if (GlobalContextTable::Lookup(global_context, name, &lookup)) { | 526 if (ScriptContextTable::Lookup(script_context, name, &lookup)) { |
| 527 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) { | 527 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) { |
| 528 return ThrowRedeclarationError(isolate, name); | 528 return ThrowRedeclarationError(isolate, name); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 if (IsLexicalVariableMode(mode)) { | 532 if (IsLexicalVariableMode(mode)) { |
| 533 LookupIterator it(global_object, name, | 533 LookupIterator it(global_object, name, |
| 534 LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 534 LookupIterator::HIDDEN_SKIP_INTERCEPTOR); |
| 535 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 535 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
| 536 if (!maybe.has_value) return isolate->heap()->exception(); | 536 if (!maybe.has_value) return isolate->heap()->exception(); |
| 537 if ((maybe.value & DONT_DELETE) != 0) { | 537 if ((maybe.value & DONT_DELETE) != 0) { |
| 538 return ThrowRedeclarationError(isolate, name); | 538 return ThrowRedeclarationError(isolate, name); |
| 539 } | 539 } |
| 540 | 540 |
| 541 GlobalObject::InvalidatePropertyCell(global_object, name); | 541 GlobalObject::InvalidatePropertyCell(global_object, name); |
| 542 } | 542 } |
| 543 } | 543 } |
| 544 return isolate->heap()->undefined_value(); | 544 return isolate->heap()->undefined_value(); |
| 545 } | 545 } |
| 546 | 546 |
| 547 | 547 |
| 548 RUNTIME_FUNCTION(Runtime_NewGlobalContext) { | 548 RUNTIME_FUNCTION(Runtime_NewScriptContext) { |
| 549 HandleScope scope(isolate); | 549 HandleScope scope(isolate); |
| 550 DCHECK(args.length() == 2); | 550 DCHECK(args.length() == 2); |
| 551 | 551 |
| 552 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 552 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| 553 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); | 553 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); |
| 554 Handle<GlobalObject> global_object(function->context()->global_object()); | 554 Handle<GlobalObject> global_object(function->context()->global_object()); |
| 555 Handle<Context> native_context(global_object->native_context()); | 555 Handle<Context> native_context(global_object->native_context()); |
| 556 Handle<GlobalContextTable> global_context_table( | 556 Handle<ScriptContextTable> script_context_table( |
| 557 native_context->global_context_table()); | 557 native_context->script_context_table()); |
| 558 | 558 |
| 559 Handle<String> clashed_name; | 559 Handle<String> clashed_name; |
| 560 Object* name_clash_result = | 560 Object* name_clash_result = |
| 561 FindNameClash(scope_info, global_object, global_context_table); | 561 FindNameClash(scope_info, global_object, script_context_table); |
| 562 if (isolate->has_pending_exception()) return name_clash_result; | 562 if (isolate->has_pending_exception()) return name_clash_result; |
| 563 | 563 |
| 564 Handle<Context> result = | 564 Handle<Context> result = |
| 565 isolate->factory()->NewGlobalContext(function, scope_info); | 565 isolate->factory()->NewScriptContext(function, scope_info); |
| 566 | 566 |
| 567 DCHECK(function->context() == isolate->context()); | 567 DCHECK(function->context() == isolate->context()); |
| 568 DCHECK(function->context()->global_object() == result->global_object()); | 568 DCHECK(function->context()->global_object() == result->global_object()); |
| 569 | 569 |
| 570 Handle<GlobalContextTable> new_global_context_table = | 570 Handle<ScriptContextTable> new_script_context_table = |
| 571 GlobalContextTable::Extend(global_context_table, result); | 571 ScriptContextTable::Extend(script_context_table, result); |
| 572 native_context->set_global_context_table(*new_global_context_table); | 572 native_context->set_script_context_table(*new_script_context_table); |
| 573 return *result; | 573 return *result; |
| 574 } | 574 } |
| 575 | 575 |
| 576 | 576 |
| 577 RUNTIME_FUNCTION(Runtime_NewFunctionContext) { | 577 RUNTIME_FUNCTION(Runtime_NewFunctionContext) { |
| 578 HandleScope scope(isolate); | 578 HandleScope scope(isolate); |
| 579 DCHECK(args.length() == 1); | 579 DCHECK(args.length() == 1); |
| 580 | 580 |
| 581 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 581 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| 582 | 582 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 } | 672 } |
| 673 | 673 |
| 674 | 674 |
| 675 RUNTIME_FUNCTION(Runtime_PushModuleContext) { | 675 RUNTIME_FUNCTION(Runtime_PushModuleContext) { |
| 676 SealHandleScope shs(isolate); | 676 SealHandleScope shs(isolate); |
| 677 DCHECK(args.length() == 2); | 677 DCHECK(args.length() == 2); |
| 678 CONVERT_SMI_ARG_CHECKED(index, 0); | 678 CONVERT_SMI_ARG_CHECKED(index, 0); |
| 679 | 679 |
| 680 if (!args[1]->IsScopeInfo()) { | 680 if (!args[1]->IsScopeInfo()) { |
| 681 // Module already initialized. Find hosting context and retrieve context. | 681 // Module already initialized. Find hosting context and retrieve context. |
| 682 Context* host = Context::cast(isolate->context())->global_context(); | 682 Context* host = Context::cast(isolate->context())->script_context(); |
| 683 Context* context = Context::cast(host->get(index)); | 683 Context* context = Context::cast(host->get(index)); |
| 684 DCHECK(context->previous() == isolate->context()); | 684 DCHECK(context->previous() == isolate->context()); |
| 685 isolate->set_context(context); | 685 isolate->set_context(context); |
| 686 return context; | 686 return context; |
| 687 } | 687 } |
| 688 | 688 |
| 689 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); | 689 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); |
| 690 | 690 |
| 691 // Allocate module context. | 691 // Allocate module context. |
| 692 HandleScope scope(isolate); | 692 HandleScope scope(isolate); |
| 693 Factory* factory = isolate->factory(); | 693 Factory* factory = isolate->factory(); |
| 694 Handle<Context> context = factory->NewModuleContext(scope_info); | 694 Handle<Context> context = factory->NewModuleContext(scope_info); |
| 695 Handle<JSModule> module = factory->NewJSModule(context, scope_info); | 695 Handle<JSModule> module = factory->NewJSModule(context, scope_info); |
| 696 context->set_module(*module); | 696 context->set_module(*module); |
| 697 Context* previous = isolate->context(); | 697 Context* previous = isolate->context(); |
| 698 context->set_previous(previous); | 698 context->set_previous(previous); |
| 699 context->set_closure(previous->closure()); | 699 context->set_closure(previous->closure()); |
| 700 context->set_global_object(previous->global_object()); | 700 context->set_global_object(previous->global_object()); |
| 701 isolate->set_context(*context); | 701 isolate->set_context(*context); |
| 702 | 702 |
| 703 // Find hosting scope and initialize internal variable holding module there. | 703 // Find hosting scope and initialize internal variable holding module there. |
| 704 previous->global_context()->set(index, *context); | 704 previous->script_context()->set(index, *context); |
| 705 | 705 |
| 706 return *context; | 706 return *context; |
| 707 } | 707 } |
| 708 | 708 |
| 709 | 709 |
| 710 RUNTIME_FUNCTION(Runtime_DeclareModules) { | 710 RUNTIME_FUNCTION(Runtime_DeclareModules) { |
| 711 HandleScope scope(isolate); | 711 HandleScope scope(isolate); |
| 712 DCHECK(args.length() == 1); | 712 DCHECK(args.length() == 1); |
| 713 CONVERT_ARG_HANDLE_CHECKED(FixedArray, descriptions, 0); | 713 CONVERT_ARG_HANDLE_CHECKED(FixedArray, descriptions, 0); |
| 714 Context* host_context = isolate->context(); | 714 Context* host_context = isolate->context(); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 return Smi::FromInt(frame->GetArgumentsLength()); | 1069 return Smi::FromInt(frame->GetArgumentsLength()); |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 | 1072 |
| 1073 RUNTIME_FUNCTION(RuntimeReference_Arguments) { | 1073 RUNTIME_FUNCTION(RuntimeReference_Arguments) { |
| 1074 SealHandleScope shs(isolate); | 1074 SealHandleScope shs(isolate); |
| 1075 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); | 1075 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); |
| 1076 } | 1076 } |
| 1077 } | 1077 } |
| 1078 } // namespace v8::internal | 1078 } // namespace v8::internal |
| OLD | NEW |