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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 isolate, Object::SetProperty(global, name, value, language_mode)); | 220 isolate, Object::SetProperty(global, name, value, language_mode)); |
221 } | 221 } |
222 | 222 |
223 namespace { | 223 namespace { |
224 | 224 |
225 Object* DeclareEvalHelper(Isolate* isolate, Handle<String> name, | 225 Object* DeclareEvalHelper(Isolate* isolate, Handle<String> name, |
226 Handle<Object> value) { | 226 Handle<Object> value) { |
227 // Declarations are always made in a function, native, or script context, or | 227 // Declarations are always made in a function, native, or script context, or |
228 // a declaration block scope. Since this is called from eval, the context | 228 // a declaration block scope. Since this is called from eval, the context |
229 // passed is the context of the caller, which may be some nested context and | 229 // passed is the context of the caller, which may be some nested context and |
230 // not the declaration context. | 230 // not the declaration context. |
neis
2016/12/14 13:59:37
Comment needs an update.
Dan Ehrenberg
2016/12/14 22:53:31
Added eval to the list. Added a test for the funct
| |
231 Handle<Context> context_arg(isolate->context(), isolate); | 231 Handle<Context> context_arg(isolate->context(), isolate); |
232 Handle<Context> context(context_arg->declaration_context(), isolate); | 232 Handle<Context> context(context_arg->declaration_context(), isolate); |
233 | 233 |
234 DCHECK(context->IsFunctionContext() || context->IsNativeContext() || | 234 DCHECK(context->IsFunctionContext() || context->IsNativeContext() || |
235 context->IsScriptContext() || | 235 context->IsScriptContext() || context->IsEvalContext() || |
236 (context->IsBlockContext() && context->has_extension())); | 236 (context->IsBlockContext() && context->has_extension())); |
237 | 237 |
238 bool is_function = value->IsJSFunction(); | 238 bool is_function = value->IsJSFunction(); |
239 bool is_var = !is_function; | 239 bool is_var = !is_function; |
240 DCHECK(!is_var || value->IsUndefined(isolate)); | 240 DCHECK(!is_var || value->IsUndefined(isolate)); |
241 | 241 |
242 int index; | 242 int index; |
243 PropertyAttributes attributes; | 243 PropertyAttributes attributes; |
244 InitializationFlag init_flag; | 244 InitializationFlag init_flag; |
245 VariableMode mode; | 245 VariableMode mode; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 object = isolate->factory()->NewJSObject( | 306 object = isolate->factory()->NewJSObject( |
307 isolate->context_extension_function()); | 307 isolate->context_extension_function()); |
308 Handle<HeapObject> extension = isolate->factory()->NewContextExtension( | 308 Handle<HeapObject> extension = isolate->factory()->NewContextExtension( |
309 handle(context->scope_info()), object); | 309 handle(context->scope_info()), object); |
310 context->set_extension(*extension); | 310 context->set_extension(*extension); |
311 } else { | 311 } else { |
312 object = handle(context->extension_object(), isolate); | 312 object = handle(context->extension_object(), isolate); |
313 } | 313 } |
314 DCHECK(object->IsJSContextExtensionObject() || object->IsJSGlobalObject()); | 314 DCHECK(object->IsJSContextExtensionObject() || object->IsJSGlobalObject()); |
315 } else { | 315 } else { |
316 // Sloppy eval will never have an extension object, as vars are hoisted out, | |
317 // and lets are known statically. | |
316 DCHECK(context->IsFunctionContext()); | 318 DCHECK(context->IsFunctionContext()); |
317 object = | 319 object = |
318 isolate->factory()->NewJSObject(isolate->context_extension_function()); | 320 isolate->factory()->NewJSObject(isolate->context_extension_function()); |
319 context->set_extension(*object); | 321 context->set_extension(*object); |
320 } | 322 } |
321 | 323 |
322 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( | 324 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( |
323 object, name, value, NONE)); | 325 object, name, value, NONE)); |
324 | 326 |
325 return isolate->heap()->undefined_value(); | 327 return isolate->heap()->undefined_value(); |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 | 697 |
696 DCHECK(function->context() == isolate->context()); | 698 DCHECK(function->context() == isolate->context()); |
697 DCHECK(*global_object == result->global_object()); | 699 DCHECK(*global_object == result->global_object()); |
698 | 700 |
699 Handle<ScriptContextTable> new_script_context_table = | 701 Handle<ScriptContextTable> new_script_context_table = |
700 ScriptContextTable::Extend(script_context_table, result); | 702 ScriptContextTable::Extend(script_context_table, result); |
701 native_context->set_script_context_table(*new_script_context_table); | 703 native_context->set_script_context_table(*new_script_context_table); |
702 return *result; | 704 return *result; |
703 } | 705 } |
704 | 706 |
705 | |
706 RUNTIME_FUNCTION(Runtime_NewFunctionContext) { | 707 RUNTIME_FUNCTION(Runtime_NewFunctionContext) { |
707 HandleScope scope(isolate); | 708 HandleScope scope(isolate); |
708 DCHECK(args.length() == 1); | 709 DCHECK(args.length() == 2); |
709 | 710 |
710 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 711 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
712 CONVERT_SMI_ARG_CHECKED(scope_type, 1); | |
711 | 713 |
712 DCHECK(function->context() == isolate->context()); | 714 DCHECK(function->context() == isolate->context()); |
713 int length = function->shared()->scope_info()->ContextLength(); | 715 int length = function->shared()->scope_info()->ContextLength(); |
714 return *isolate->factory()->NewFunctionContext(length, function); | 716 return *isolate->factory()->NewFunctionContext( |
717 length, function, static_cast<ScopeType>(scope_type)); | |
715 } | 718 } |
716 | 719 |
717 | |
718 RUNTIME_FUNCTION(Runtime_PushWithContext) { | 720 RUNTIME_FUNCTION(Runtime_PushWithContext) { |
719 HandleScope scope(isolate); | 721 HandleScope scope(isolate); |
720 DCHECK_EQ(3, args.length()); | 722 DCHECK_EQ(3, args.length()); |
721 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, extension_object, 0); | 723 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, extension_object, 0); |
722 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); | 724 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); |
723 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); | 725 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 2); |
724 Handle<Context> current(isolate->context()); | 726 Handle<Context> current(isolate->context()); |
725 Handle<Context> context = isolate->factory()->NewWithContext( | 727 Handle<Context> context = isolate->factory()->NewWithContext( |
726 function, current, scope_info, extension_object); | 728 function, current, scope_info, extension_object); |
727 isolate->set_context(*context); | 729 isolate->set_context(*context); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
974 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { | 976 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { |
975 HandleScope scope(isolate); | 977 HandleScope scope(isolate); |
976 DCHECK_EQ(2, args.length()); | 978 DCHECK_EQ(2, args.length()); |
977 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 979 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
978 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 980 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
979 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); | 981 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); |
980 } | 982 } |
981 | 983 |
982 } // namespace internal | 984 } // namespace internal |
983 } // namespace v8 | 985 } // namespace v8 |
OLD | NEW |