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

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

Issue 705663004: harmony_scoping: Implement lexical bindings at top level (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 1); 500 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 1);
501 CONVERT_BOOLEAN_ARG_CHECKED(pretenure, 2); 501 CONVERT_BOOLEAN_ARG_CHECKED(pretenure, 2);
502 502
503 // The caller ensures that we pretenure closures that are assigned 503 // The caller ensures that we pretenure closures that are assigned
504 // directly to properties. 504 // directly to properties.
505 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; 505 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED;
506 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, 506 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context,
507 pretenure_flag); 507 pretenure_flag);
508 } 508 }
509 509
510 static bool FindNameClash(Handle<ScopeInfo> scope_info,
511 Handle<GlobalContextTable> global_context,
512 Handle<String>* clashed_name) {
513 for (int var = 0; var < scope_info->ContextLocalCount(); var++) {
514 Handle<String> name(scope_info->ContextLocalName(var));
515 VariableMode mode = scope_info->ContextLocalMode(var);
516 GlobalContextTable::LookupResult lookup;
517 if (GlobalContextTable::Lookup(global_context, name, &lookup)) {
518 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode_)) {
rossberg 2014/11/06 12:29:12 Are non-lexical variables actually included in tho
Dmitry Lomov (no reviews) 2014/11/06 17:26:58 All done (I kept IsLexicalVariableMode(lookup.mode
519 *clashed_name = name;
520 return true;
521 }
522 }
523 }
524 return false;
525 }
526
510 527
511 RUNTIME_FUNCTION(Runtime_NewGlobalContext) { 528 RUNTIME_FUNCTION(Runtime_NewGlobalContext) {
512 HandleScope scope(isolate); 529 HandleScope scope(isolate);
513 DCHECK(args.length() == 2); 530 DCHECK(args.length() == 2);
514 531
515 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 532 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
516 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); 533 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1);
534 Handle<Context> native_context(
535 function->context()->global_object()->native_context());
536 Handle<GlobalContextTable> global_context_table(
537 native_context->global_context_table());
538
539 Handle<String> clashed_name;
540 if (FindNameClash(scope_info, global_context_table, &clashed_name)) {
rossberg 2014/11/06 12:29:12 Now that the checking this is a runtime thing and
Dmitry Lomov (no reviews) 2014/11/06 17:26:58 Yes, I will clean it up in separate CL
541 return ThrowRedeclarationError(isolate, clashed_name);
542 }
543
517 Handle<Context> result = 544 Handle<Context> result =
518 isolate->factory()->NewGlobalContext(function, scope_info); 545 isolate->factory()->NewGlobalContext(function, scope_info);
519 546
520 DCHECK(function->context() == isolate->context()); 547 DCHECK(function->context() == isolate->context());
521 DCHECK(function->context()->global_object() == result->global_object()); 548 DCHECK(function->context()->global_object() == result->global_object());
522 result->global_object()->set_global_context(*result); 549
rossberg 2014/11/06 12:29:12 Can't the global_context property on the global ob
Dmitry Lomov (no reviews) 2014/11/06 17:26:58 Yes, I will do the cleanup in separate CL.
550 Handle<GlobalContextTable> new_global_context_table =
551 GlobalContextTable::Extend(global_context_table, result);
552 native_context->set_global_context_table(*new_global_context_table);
523 return *result; 553 return *result;
524 } 554 }
525 555
526 556
527 RUNTIME_FUNCTION(Runtime_NewFunctionContext) { 557 RUNTIME_FUNCTION(Runtime_NewFunctionContext) {
528 HandleScope scope(isolate); 558 HandleScope scope(isolate);
529 DCHECK(args.length() == 1); 559 DCHECK(args.length() == 1);
530 560
531 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 561 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
532 562
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 return Smi::FromInt(frame->GetArgumentsLength()); 1049 return Smi::FromInt(frame->GetArgumentsLength());
1020 } 1050 }
1021 1051
1022 1052
1023 RUNTIME_FUNCTION(RuntimeReference_Arguments) { 1053 RUNTIME_FUNCTION(RuntimeReference_Arguments) {
1024 SealHandleScope shs(isolate); 1054 SealHandleScope shs(isolate);
1025 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); 1055 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate);
1026 } 1056 }
1027 } 1057 }
1028 } // namespace v8::internal 1058 } // namespace v8::internal
OLDNEW
« src/contexts.cc ('K') | « src/objects-inl.h ('k') | test/cctest/test-decls.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698