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