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

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

Issue 1097283003: Resolve references to "this" the same way as normal variables (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Add tests for "this" scoping in arrow functions Created 5 years, 8 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
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/runtime/runtime-utils.h" 10 #include "src/runtime/runtime-utils.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (attributes != ABSENT && holder->IsJSGlobalObject()) { 242 if (attributes != ABSENT && holder->IsJSGlobalObject()) {
243 return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name, 243 return DeclareGlobals(isolate, Handle<JSGlobalObject>::cast(holder), name,
244 value, attr, is_var, is_const, is_function); 244 value, attr, is_var, is_const, is_function);
245 } 245 }
246 if (context_arg->has_extension() && 246 if (context_arg->has_extension() &&
247 context_arg->extension()->IsJSGlobalObject()) { 247 context_arg->extension()->IsJSGlobalObject()) {
248 Handle<JSGlobalObject> global( 248 Handle<JSGlobalObject> global(
249 JSGlobalObject::cast(context_arg->extension()), isolate); 249 JSGlobalObject::cast(context_arg->extension()), isolate);
250 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const, 250 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const,
251 is_function); 251 is_function);
252 } else if (context->IsScriptContext()) {
253 DCHECK(context->global_object()->IsJSGlobalObject());
254 Handle<JSGlobalObject> global(
255 JSGlobalObject::cast(context->global_object()), isolate);
256 return DeclareGlobals(isolate, global, name, value, attr, is_var, is_const,
257 is_function);
252 } 258 }
253 259
254 if (attributes != ABSENT) { 260 if (attributes != ABSENT) {
255 // The name was declared before; check for conflicting re-declarations. 261 // The name was declared before; check for conflicting re-declarations.
256 if (is_const || (attributes & READ_ONLY) != 0) { 262 if (is_const || (attributes & READ_ONLY) != 0) {
257 return ThrowRedeclarationError(isolate, name); 263 return ThrowRedeclarationError(isolate, name);
258 } 264 }
259 265
260 // Skip var re-declarations. 266 // Skip var re-declarations.
261 if (is_var) return isolate->heap()->undefined_value(); 267 if (is_var) return isolate->heap()->undefined_value();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 PropertyAttributes attr = 323 PropertyAttributes attr =
318 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); 324 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY);
319 325
320 // Strict mode handling not needed (legacy const is disallowed in strict 326 // Strict mode handling not needed (legacy const is disallowed in strict
321 // mode). 327 // mode).
322 328
323 // The declared const was configurable, and may have been deleted in the 329 // The declared const was configurable, and may have been deleted in the
324 // meanwhile. If so, re-introduce the variable in the context extension. 330 // meanwhile. If so, re-introduce the variable in the context extension.
325 if (attributes == ABSENT) { 331 if (attributes == ABSENT) {
326 Handle<Context> declaration_context(context_arg->declaration_context()); 332 Handle<Context> declaration_context(context_arg->declaration_context());
327 DCHECK(declaration_context->has_extension()); 333 if (declaration_context->IsScriptContext()) {
328 holder = handle(declaration_context->extension(), isolate); 334 holder = handle(declaration_context->global_object(), isolate);
335 } else {
336 DCHECK(declaration_context->has_extension());
337 holder = handle(declaration_context->extension(), isolate);
338 }
329 CHECK(holder->IsJSObject()); 339 CHECK(holder->IsJSObject());
330 } else { 340 } else {
331 // For JSContextExtensionObjects, the initializer can be run multiple times 341 // For JSContextExtensionObjects, the initializer can be run multiple times
332 // if in a for loop: for (var i = 0; i < 2; i++) { const x = i; }. Only the 342 // if in a for loop: for (var i = 0; i < 2; i++) { const x = i; }. Only the
333 // first assignment should go through. For JSGlobalObjects, additionally any 343 // first assignment should go through. For JSGlobalObjects, additionally any
334 // code can run in between that modifies the declared property. 344 // code can run in between that modifies the declared property.
335 DCHECK(holder->IsJSGlobalObject() || holder->IsJSContextExtensionObject()); 345 DCHECK(holder->IsJSGlobalObject() || holder->IsJSContextExtensionObject());
336 346
337 LookupIterator it(holder, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); 347 LookupIterator it(holder, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
338 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); 348 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 return Smi::FromInt(frame->GetArgumentsLength()); 1129 return Smi::FromInt(frame->GetArgumentsLength());
1120 } 1130 }
1121 1131
1122 1132
1123 RUNTIME_FUNCTION(Runtime_Arguments) { 1133 RUNTIME_FUNCTION(Runtime_Arguments) {
1124 SealHandleScope shs(isolate); 1134 SealHandleScope shs(isolate);
1125 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); 1135 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate);
1126 } 1136 }
1127 } 1137 }
1128 } // namespace v8::internal 1138 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime-debug.cc ('k') | src/scopeinfo.cc » ('j') | src/scopes.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698