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/messages.h" | 10 #include "src/messages.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 if (attributes != ABSENT && holder->IsJSGlobalObject()) { | 241 if (attributes != ABSENT && holder->IsJSGlobalObject()) { |
242 return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name, | 242 return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name, |
243 value, attr, is_var, is_const, is_function); | 243 value, attr, is_var, is_const, is_function); |
244 } | 244 } |
245 if (context_arg->has_extension() && | 245 if (context_arg->has_extension() && |
246 context_arg->extension()->IsJSGlobalObject()) { | 246 context_arg->extension()->IsJSGlobalObject()) { |
247 Handle<JSGlobalObject> global( | 247 Handle<JSGlobalObject> global( |
248 JSGlobalObject::cast(context_arg->extension()), isolate); | 248 JSGlobalObject::cast(context_arg->extension()), isolate); |
249 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const, | 249 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const, |
250 is_function); | 250 is_function); |
251 } else if (context->IsScriptContext()) { | |
252 DCHECK(context->global_object()->IsJSGlobalObject()); | |
253 Handle<JSGlobalObject> global( | |
254 JSGlobalObject::cast(context->global_object()), isolate); | |
255 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const, | |
256 is_function); | |
257 } | 251 } |
258 | 252 |
259 if (attributes != ABSENT) { | 253 if (attributes != ABSENT) { |
260 // The name was declared before; check for conflicting re-declarations. | 254 // The name was declared before; check for conflicting re-declarations. |
261 if (is_const || (attributes & READ_ONLY) != 0) { | 255 if (is_const || (attributes & READ_ONLY) != 0) { |
262 return ThrowRedeclarationError(isolate, name); | 256 return ThrowRedeclarationError(isolate, name); |
263 } | 257 } |
264 | 258 |
265 // Skip var re-declarations. | 259 // Skip var re-declarations. |
266 if (is_var) return isolate->heap()->undefined_value(); | 260 if (is_var) return isolate->heap()->undefined_value(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 PropertyAttributes attr = | 316 PropertyAttributes attr = |
323 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); | 317 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); |
324 | 318 |
325 // Strict mode handling not needed (legacy const is disallowed in strict | 319 // Strict mode handling not needed (legacy const is disallowed in strict |
326 // mode). | 320 // mode). |
327 | 321 |
328 // The declared const was configurable, and may have been deleted in the | 322 // The declared const was configurable, and may have been deleted in the |
329 // meanwhile. If so, re-introduce the variable in the context extension. | 323 // meanwhile. If so, re-introduce the variable in the context extension. |
330 if (attributes == ABSENT) { | 324 if (attributes == ABSENT) { |
331 Handle<Context> declaration_context(context_arg->declaration_context()); | 325 Handle<Context> declaration_context(context_arg->declaration_context()); |
332 if (declaration_context->IsScriptContext()) { | 326 DCHECK(declaration_context->has_extension()); |
333 holder = handle(declaration_context->global_object(), isolate); | 327 holder = handle(declaration_context->extension(), isolate); |
334 } else { | |
335 DCHECK(declaration_context->has_extension()); | |
336 holder = handle(declaration_context->extension(), isolate); | |
337 } | |
338 CHECK(holder->IsJSObject()); | 328 CHECK(holder->IsJSObject()); |
339 } else { | 329 } else { |
340 // For JSContextExtensionObjects, the initializer can be run multiple times | 330 // For JSContextExtensionObjects, the initializer can be run multiple times |
341 // if in a for loop: for (var i = 0; i < 2; i++) { const x = i; }. Only the | 331 // if in a for loop: for (var i = 0; i < 2; i++) { const x = i; }. Only the |
342 // first assignment should go through. For JSGlobalObjects, additionally any | 332 // first assignment should go through. For JSGlobalObjects, additionally any |
343 // code can run in between that modifies the declared property. | 333 // code can run in between that modifies the declared property. |
344 DCHECK(holder->IsJSGlobalObject() || holder->IsJSContextExtensionObject()); | 334 DCHECK(holder->IsJSGlobalObject() || holder->IsJSContextExtensionObject()); |
345 | 335 |
346 LookupIterator it(holder, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 336 LookupIterator it(holder, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); |
347 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 337 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 Handle<GlobalObject> global_object(function->context()->global_object()); | 621 Handle<GlobalObject> global_object(function->context()->global_object()); |
632 Handle<Context> native_context(global_object->native_context()); | 622 Handle<Context> native_context(global_object->native_context()); |
633 Handle<ScriptContextTable> script_context_table( | 623 Handle<ScriptContextTable> script_context_table( |
634 native_context->script_context_table()); | 624 native_context->script_context_table()); |
635 | 625 |
636 Handle<String> clashed_name; | 626 Handle<String> clashed_name; |
637 Object* name_clash_result = | 627 Object* name_clash_result = |
638 FindNameClash(scope_info, global_object, script_context_table); | 628 FindNameClash(scope_info, global_object, script_context_table); |
639 if (isolate->has_pending_exception()) return name_clash_result; | 629 if (isolate->has_pending_exception()) return name_clash_result; |
640 | 630 |
641 // Script contexts have a canonical empty function as their closure, not the | |
642 // anonymous closure containing the global code. See | |
643 // FullCodeGenerator::PushFunctionArgumentForContextAllocation. | |
644 Handle<JSFunction> closure(native_context->closure()); | |
645 Handle<Context> result = | 631 Handle<Context> result = |
646 isolate->factory()->NewScriptContext(closure, scope_info); | 632 isolate->factory()->NewScriptContext(function, scope_info); |
647 | 633 |
648 DCHECK(function->context() == isolate->context()); | 634 DCHECK(function->context() == isolate->context()); |
649 DCHECK(function->context()->global_object() == result->global_object()); | 635 DCHECK(function->context()->global_object() == result->global_object()); |
650 | 636 |
651 Handle<ScriptContextTable> new_script_context_table = | 637 Handle<ScriptContextTable> new_script_context_table = |
652 ScriptContextTable::Extend(script_context_table, result); | 638 ScriptContextTable::Extend(script_context_table, result); |
653 native_context->set_script_context_table(*new_script_context_table); | 639 native_context->set_script_context_table(*new_script_context_table); |
654 return *result; | 640 return *result; |
655 } | 641 } |
656 | 642 |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 return Smi::FromInt(frame->GetArgumentsLength()); | 1116 return Smi::FromInt(frame->GetArgumentsLength()); |
1131 } | 1117 } |
1132 | 1118 |
1133 | 1119 |
1134 RUNTIME_FUNCTION(Runtime_Arguments) { | 1120 RUNTIME_FUNCTION(Runtime_Arguments) { |
1135 SealHandleScope shs(isolate); | 1121 SealHandleScope shs(isolate); |
1136 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); | 1122 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); |
1137 } | 1123 } |
1138 } | 1124 } |
1139 } // namespace v8::internal | 1125 } // namespace v8::internal |
OLD | NEW |