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