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/runtime/runtime-utils.h" | 10 #include "src/runtime/runtime-utils.h" |
11 #include "src/scopeinfo.h" | 11 #include "src/scopeinfo.h" |
12 #include "src/scopes.h" | 12 #include "src/scopes.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 | 16 |
17 static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) { | 17 static Object* ThrowRedeclarationError(Isolate* isolate, Handle<String> name) { |
18 HandleScope scope(isolate); | 18 HandleScope scope(isolate); |
19 Handle<Object> args[1] = {name}; | 19 Handle<Object> args[1] = {name}; |
20 THROW_NEW_ERROR_RETURN_FAILURE( | 20 THROW_NEW_ERROR_RETURN_FAILURE( |
21 isolate, NewTypeError("var_redeclaration", HandleVector(args, 1))); | 21 isolate, NewTypeError("var_redeclaration", HandleVector(args, 1))); |
22 } | 22 } |
23 | 23 |
24 | 24 |
25 // May throw a RedeclarationError. | 25 // May throw a RedeclarationError. |
26 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global, | 26 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global, |
27 Handle<String> name, Handle<Object> value, | 27 Handle<String> name, Handle<Object> value, |
28 PropertyAttributes attr, bool is_var, | 28 PropertyAttributes attr, bool is_var, |
29 bool is_const, bool is_function) { | 29 bool is_const, bool is_function) { |
30 Handle<GlobalContextTable> global_contexts( | |
31 global->native_context()->global_context_table()); | |
32 GlobalContextTable::LookupResult lookup; | |
33 if (GlobalContextTable::Lookup(global_contexts, name, &lookup) && | |
34 IsLexicalVariableMode(lookup.mode)) { | |
35 return ThrowRedeclarationError(isolate, name); | |
36 } | |
37 | |
30 // Do the lookup own properties only, see ES5 erratum. | 38 // Do the lookup own properties only, see ES5 erratum. |
31 LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | 39 LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); |
32 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | 40 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); |
33 if (!maybe.has_value) return isolate->heap()->exception(); | 41 if (!maybe.has_value) return isolate->heap()->exception(); |
34 | 42 |
35 if (it.IsFound()) { | 43 if (it.IsFound()) { |
36 PropertyAttributes old_attributes = maybe.value; | 44 PropertyAttributes old_attributes = maybe.value; |
37 // The name was declared before; check for conflicting re-declarations. | 45 // The name was declared before; check for conflicting re-declarations. |
38 if (is_const) return ThrowRedeclarationError(isolate, name); | 46 if (is_const) return ThrowRedeclarationError(isolate, name); |
39 | 47 |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 1); | 508 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 1); |
501 CONVERT_BOOLEAN_ARG_CHECKED(pretenure, 2); | 509 CONVERT_BOOLEAN_ARG_CHECKED(pretenure, 2); |
502 | 510 |
503 // The caller ensures that we pretenure closures that are assigned | 511 // The caller ensures that we pretenure closures that are assigned |
504 // directly to properties. | 512 // directly to properties. |
505 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; | 513 PretenureFlag pretenure_flag = pretenure ? TENURED : NOT_TENURED; |
506 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, | 514 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, |
507 pretenure_flag); | 515 pretenure_flag); |
508 } | 516 } |
509 | 517 |
518 static Object* FindNameClash(Handle<ScopeInfo> scope_info, | |
adamk
2014/11/06 20:18:06
Not necessary in this patch, but this file could u
Dmitry Lomov (no reviews)
2014/11/07 10:18:48
Indeed. I'll prep a clean-up patch.
| |
519 Handle<GlobalObject> global_object, | |
520 Handle<GlobalContextTable> global_context) { | |
521 Isolate* isolate = scope_info->GetIsolate(); | |
522 for (int var = 0; var < scope_info->ContextLocalCount(); var++) { | |
523 Handle<String> name(scope_info->ContextLocalName(var)); | |
524 VariableMode mode = scope_info->ContextLocalMode(var); | |
525 GlobalContextTable::LookupResult lookup; | |
526 if (GlobalContextTable::Lookup(global_context, name, &lookup)) { | |
527 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) { | |
528 return ThrowRedeclarationError(isolate, name); | |
529 } | |
530 } | |
531 | |
532 if (IsLexicalVariableMode(mode)) { | |
533 LookupIterator it(global_object, name, | |
534 LookupIterator::HIDDEN_SKIP_INTERCEPTOR); | |
535 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); | |
536 if (!maybe.has_value) return isolate->heap()->exception(); | |
adamk
2014/11/06 20:18:06
Why return exception here?
Dmitry Lomov (no reviews)
2014/11/07 10:18:48
Absence of value in Maybe<T> indicates exception,
| |
537 if ((maybe.value & DONT_DELETE) != 0) { | |
538 return ThrowRedeclarationError(isolate, name); | |
539 } | |
540 | |
541 GlobalObject::InvalidatePropertyCell(global_object, name); | |
542 } | |
543 } | |
544 return isolate->heap()->undefined_value(); | |
545 } | |
546 | |
510 | 547 |
511 RUNTIME_FUNCTION(Runtime_NewGlobalContext) { | 548 RUNTIME_FUNCTION(Runtime_NewGlobalContext) { |
512 HandleScope scope(isolate); | 549 HandleScope scope(isolate); |
513 DCHECK(args.length() == 2); | 550 DCHECK(args.length() == 2); |
514 | 551 |
515 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 552 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
516 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); | 553 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); |
554 Handle<GlobalObject> global_object(function->context()->global_object()); | |
555 Handle<Context> native_context(global_object->native_context()); | |
556 Handle<GlobalContextTable> global_context_table( | |
557 native_context->global_context_table()); | |
558 | |
559 Handle<String> clashed_name; | |
560 Object* name_clash_result = | |
561 FindNameClash(scope_info, global_object, global_context_table); | |
562 if (isolate->has_pending_exception()) return name_clash_result; | |
563 | |
517 Handle<Context> result = | 564 Handle<Context> result = |
518 isolate->factory()->NewGlobalContext(function, scope_info); | 565 isolate->factory()->NewGlobalContext(function, scope_info); |
519 | 566 |
520 DCHECK(function->context() == isolate->context()); | 567 DCHECK(function->context() == isolate->context()); |
521 DCHECK(function->context()->global_object() == result->global_object()); | 568 DCHECK(function->context()->global_object() == result->global_object()); |
522 result->global_object()->set_global_context(*result); | 569 |
570 Handle<GlobalContextTable> new_global_context_table = | |
571 GlobalContextTable::Extend(global_context_table, result); | |
572 native_context->set_global_context_table(*new_global_context_table); | |
523 return *result; | 573 return *result; |
524 } | 574 } |
525 | 575 |
526 | 576 |
527 RUNTIME_FUNCTION(Runtime_NewFunctionContext) { | 577 RUNTIME_FUNCTION(Runtime_NewFunctionContext) { |
528 HandleScope scope(isolate); | 578 HandleScope scope(isolate); |
529 DCHECK(args.length() == 1); | 579 DCHECK(args.length() == 1); |
530 | 580 |
531 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); | 581 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
532 | 582 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1019 return Smi::FromInt(frame->GetArgumentsLength()); | 1069 return Smi::FromInt(frame->GetArgumentsLength()); |
1020 } | 1070 } |
1021 | 1071 |
1022 | 1072 |
1023 RUNTIME_FUNCTION(RuntimeReference_Arguments) { | 1073 RUNTIME_FUNCTION(RuntimeReference_Arguments) { |
1024 SealHandleScope shs(isolate); | 1074 SealHandleScope shs(isolate); |
1025 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); | 1075 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); |
1026 } | 1076 } |
1027 } | 1077 } |
1028 } // namespace v8::internal | 1078 } // namespace v8::internal |
OLD | NEW |