Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: src/runtime/runtime-scopes.cc

Issue 1136073002: Resolve references to "this" the same way as normal variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: "this" should never be looked up dynamically Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if (attributes != ABSENT && holder->IsJSGlobalObject()) { 243 if (attributes != ABSENT && holder->IsJSGlobalObject()) {
244 return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name, 244 return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name,
245 value, attr, is_var, is_const, is_function); 245 value, attr, is_var, is_const, is_function);
246 } 246 }
247 if (context_arg->has_extension() && 247 if (context_arg->has_extension() &&
248 context_arg->extension()->IsJSGlobalObject()) { 248 context_arg->extension()->IsJSGlobalObject()) {
249 Handle<JSGlobalObject> global( 249 Handle<JSGlobalObject> global(
250 JSGlobalObject::cast(context_arg->extension()), isolate); 250 JSGlobalObject::cast(context_arg->extension()), isolate);
251 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const, 251 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const,
252 is_function); 252 is_function);
253 } else if (context->IsScriptContext()) {
254 DCHECK(context->global_object()->IsJSGlobalObject());
255 Handle<JSGlobalObject> global(
256 JSGlobalObject::cast(context->global_object()), isolate);
257 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const,
258 is_function);
253 } 259 }
254 260
255 if (attributes != ABSENT) { 261 if (attributes != ABSENT) {
256 // The name was declared before; check for conflicting re-declarations. 262 // The name was declared before; check for conflicting re-declarations.
257 if (is_const || (attributes & READ_ONLY) != 0) { 263 if (is_const || (attributes & READ_ONLY) != 0) {
258 return ThrowRedeclarationError(isolate, name); 264 return ThrowRedeclarationError(isolate, name);
259 } 265 }
260 266
261 // Skip var re-declarations. 267 // Skip var re-declarations.
262 if (is_var) return isolate->heap()->undefined_value(); 268 if (is_var) return isolate->heap()->undefined_value();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 PropertyAttributes attr = 324 PropertyAttributes attr =
319 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); 325 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY);
320 326
321 // Strict mode handling not needed (legacy const is disallowed in strict 327 // Strict mode handling not needed (legacy const is disallowed in strict
322 // mode). 328 // mode).
323 329
324 // The declared const was configurable, and may have been deleted in the 330 // The declared const was configurable, and may have been deleted in the
325 // meanwhile. If so, re-introduce the variable in the context extension. 331 // meanwhile. If so, re-introduce the variable in the context extension.
326 if (attributes == ABSENT) { 332 if (attributes == ABSENT) {
327 Handle<Context> declaration_context(context_arg->declaration_context()); 333 Handle<Context> declaration_context(context_arg->declaration_context());
328 DCHECK(declaration_context->has_extension()); 334 if (declaration_context->IsScriptContext()) {
329 holder = handle(declaration_context->extension(), isolate); 335 holder = handle(declaration_context->global_object(), isolate);
336 } else {
337 DCHECK(declaration_context->has_extension());
338 holder = handle(declaration_context->extension(), isolate);
339 }
330 CHECK(holder->IsJSObject()); 340 CHECK(holder->IsJSObject());
331 } else { 341 } else {
332 // For JSContextExtensionObjects, the initializer can be run multiple times 342 // For JSContextExtensionObjects, the initializer can be run multiple times
333 // if in a for loop: for (var i = 0; i < 2; i++) { const x = i; }. Only the 343 // if in a for loop: for (var i = 0; i < 2; i++) { const x = i; }. Only the
334 // first assignment should go through. For JSGlobalObjects, additionally any 344 // first assignment should go through. For JSGlobalObjects, additionally any
335 // code can run in between that modifies the declared property. 345 // code can run in between that modifies the declared property.
336 DCHECK(holder->IsJSGlobalObject() || holder->IsJSContextExtensionObject()); 346 DCHECK(holder->IsJSGlobalObject() || holder->IsJSContextExtensionObject());
337 347
338 LookupIterator it(holder, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); 348 LookupIterator it(holder, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
339 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); 349 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 Handle<GlobalObject> global_object(function->context()->global_object()); 633 Handle<GlobalObject> global_object(function->context()->global_object());
624 Handle<Context> native_context(global_object->native_context()); 634 Handle<Context> native_context(global_object->native_context());
625 Handle<ScriptContextTable> script_context_table( 635 Handle<ScriptContextTable> script_context_table(
626 native_context->script_context_table()); 636 native_context->script_context_table());
627 637
628 Handle<String> clashed_name; 638 Handle<String> clashed_name;
629 Object* name_clash_result = 639 Object* name_clash_result =
630 FindNameClash(scope_info, global_object, script_context_table); 640 FindNameClash(scope_info, global_object, script_context_table);
631 if (isolate->has_pending_exception()) return name_clash_result; 641 if (isolate->has_pending_exception()) return name_clash_result;
632 642
643 // Script contexts have a canonical empty function as their closure, not the
644 // anonymous closure containing the global code. See
645 // FullCodeGenerator::PushFunctionArgumentForContextAllocation.
646 Handle<JSFunction> closure(native_context->closure());
633 Handle<Context> result = 647 Handle<Context> result =
634 isolate->factory()->NewScriptContext(function, scope_info); 648 isolate->factory()->NewScriptContext(closure, scope_info);
635 649
636 DCHECK(function->context() == isolate->context()); 650 DCHECK(function->context() == isolate->context());
637 DCHECK(function->context()->global_object() == result->global_object()); 651 DCHECK(function->context()->global_object() == result->global_object());
638 652
639 Handle<ScriptContextTable> new_script_context_table = 653 Handle<ScriptContextTable> new_script_context_table =
640 ScriptContextTable::Extend(script_context_table, result); 654 ScriptContextTable::Extend(script_context_table, result);
641 native_context->set_script_context_table(*new_script_context_table); 655 native_context->set_script_context_table(*new_script_context_table);
642 return *result; 656 return *result;
643 } 657 }
644 658
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 return Smi::FromInt(frame->GetArgumentsLength()); 1134 return Smi::FromInt(frame->GetArgumentsLength());
1121 } 1135 }
1122 1136
1123 1137
1124 RUNTIME_FUNCTION(Runtime_Arguments) { 1138 RUNTIME_FUNCTION(Runtime_Arguments) {
1125 SealHandleScope shs(isolate); 1139 SealHandleScope shs(isolate);
1126 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); 1140 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate);
1127 } 1141 }
1128 } 1142 }
1129 } // namespace v8::internal 1143 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698