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

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

Issue 1406113007: Merge GlobalObject with JSGlobalObject. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | src/snapshot/serialize.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/runtime/runtime-utils.h" 5 #include "src/runtime/runtime-utils.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/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 12 matching lines...) Expand all
23 23
24 24
25 RUNTIME_FUNCTION(Runtime_ThrowConstAssignError) { 25 RUNTIME_FUNCTION(Runtime_ThrowConstAssignError) {
26 HandleScope scope(isolate); 26 HandleScope scope(isolate);
27 THROW_NEW_ERROR_RETURN_FAILURE(isolate, 27 THROW_NEW_ERROR_RETURN_FAILURE(isolate,
28 NewTypeError(MessageTemplate::kConstAssign)); 28 NewTypeError(MessageTemplate::kConstAssign));
29 } 29 }
30 30
31 31
32 // May throw a RedeclarationError. 32 // May throw a RedeclarationError.
33 static Object* DeclareGlobals(Isolate* isolate, Handle<GlobalObject> global, 33 static Object* DeclareGlobals(Isolate* isolate, Handle<JSGlobalObject> global,
34 Handle<String> name, Handle<Object> value, 34 Handle<String> name, Handle<Object> value,
35 PropertyAttributes attr, bool is_var, 35 PropertyAttributes attr, bool is_var,
36 bool is_const, bool is_function) { 36 bool is_const, bool is_function) {
37 Handle<ScriptContextTable> script_contexts( 37 Handle<ScriptContextTable> script_contexts(
38 global->native_context()->script_context_table()); 38 global->native_context()->script_context_table());
39 ScriptContextTable::LookupResult lookup; 39 ScriptContextTable::LookupResult lookup;
40 if (ScriptContextTable::Lookup(script_contexts, name, &lookup) && 40 if (ScriptContextTable::Lookup(script_contexts, name, &lookup) &&
41 IsLexicalVariableMode(lookup.mode)) { 41 IsLexicalVariableMode(lookup.mode)) {
42 return ThrowRedeclarationError(isolate, name); 42 return ThrowRedeclarationError(isolate, name);
43 } 43 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes( 80 RETURN_FAILURE_ON_EXCEPTION(isolate, JSObject::SetOwnPropertyIgnoreAttributes(
81 global, name, value, attr)); 81 global, name, value, attr));
82 82
83 return isolate->heap()->undefined_value(); 83 return isolate->heap()->undefined_value();
84 } 84 }
85 85
86 86
87 RUNTIME_FUNCTION(Runtime_DeclareGlobals) { 87 RUNTIME_FUNCTION(Runtime_DeclareGlobals) {
88 HandleScope scope(isolate); 88 HandleScope scope(isolate);
89 DCHECK_EQ(2, args.length()); 89 DCHECK_EQ(2, args.length());
90 Handle<GlobalObject> global(isolate->global_object()); 90 Handle<JSGlobalObject> global(isolate->global_object());
91 Handle<Context> context(isolate->context()); 91 Handle<Context> context(isolate->context());
92 92
93 CONVERT_ARG_HANDLE_CHECKED(FixedArray, pairs, 0); 93 CONVERT_ARG_HANDLE_CHECKED(FixedArray, pairs, 0);
94 CONVERT_SMI_ARG_CHECKED(flags, 1); 94 CONVERT_SMI_ARG_CHECKED(flags, 1);
95 95
96 // Traverse the name/value pairs and set the properties. 96 // Traverse the name/value pairs and set the properties.
97 int length = pairs->length(); 97 int length = pairs->length();
98 for (int i = 0; i < length; i += 2) { 98 for (int i = 0; i < length; i += 2) {
99 HandleScope scope(isolate); 99 HandleScope scope(isolate);
100 Handle<String> name(String::cast(pairs->get(i))); 100 Handle<String> name(String::cast(pairs->get(i)));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // args[2] == value (optional) 148 // args[2] == value (optional)
149 149
150 // Determine if we need to assign to the variable if it already 150 // Determine if we need to assign to the variable if it already
151 // exists (based on the number of arguments). 151 // exists (based on the number of arguments).
152 RUNTIME_ASSERT(args.length() == 3); 152 RUNTIME_ASSERT(args.length() == 3);
153 153
154 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); 154 CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
155 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 1); 155 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 1);
156 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 156 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
157 157
158 Handle<GlobalObject> global(isolate->context()->global_object()); 158 Handle<JSGlobalObject> global(isolate->context()->global_object());
159 Handle<Object> result; 159 Handle<Object> result;
160 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 160 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
161 isolate, result, Object::SetProperty(global, name, value, language_mode)); 161 isolate, result, Object::SetProperty(global, name, value, language_mode));
162 return *result; 162 return *result;
163 } 163 }
164 164
165 165
166 RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) { 166 RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) {
167 HandleScope handle_scope(isolate); 167 HandleScope handle_scope(isolate);
168 // All constants are declared with an initial value. The name 168 // All constants are declared with an initial value. The name
169 // of the constant is the first argument and the initial value 169 // of the constant is the first argument and the initial value
170 // is the second. 170 // is the second.
171 RUNTIME_ASSERT(args.length() == 2); 171 RUNTIME_ASSERT(args.length() == 2);
172 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); 172 CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
173 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); 173 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1);
174 174
175 Handle<GlobalObject> global = isolate->global_object(); 175 Handle<JSGlobalObject> global = isolate->global_object();
176 176
177 // Lookup the property as own on the global object. 177 // Lookup the property as own on the global object.
178 LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR); 178 LookupIterator it(global, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
179 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); 179 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
180 DCHECK(maybe.IsJust()); 180 DCHECK(maybe.IsJust());
181 PropertyAttributes old_attributes = maybe.FromJust(); 181 PropertyAttributes old_attributes = maybe.FromJust();
182 182
183 PropertyAttributes attr = 183 PropertyAttributes attr =
184 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY); 184 static_cast<PropertyAttributes>(DONT_DELETE | READ_ONLY);
185 // Set the value if the property is either missing, or the property attributes 185 // Set the value if the property is either missing, or the property attributes
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 DCHECK_EQ(1, args.length()); 619 DCHECK_EQ(1, args.length());
620 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); 620 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0);
621 Handle<Context> context(isolate->context(), isolate); 621 Handle<Context> context(isolate->context(), isolate);
622 // The caller ensures that we pretenure closures that are assigned 622 // The caller ensures that we pretenure closures that are assigned
623 // directly to properties. 623 // directly to properties.
624 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, 624 return *isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context,
625 TENURED); 625 TENURED);
626 } 626 }
627 627
628 static Object* FindNameClash(Handle<ScopeInfo> scope_info, 628 static Object* FindNameClash(Handle<ScopeInfo> scope_info,
629 Handle<GlobalObject> global_object, 629 Handle<JSGlobalObject> global_object,
630 Handle<ScriptContextTable> script_context) { 630 Handle<ScriptContextTable> script_context) {
631 Isolate* isolate = scope_info->GetIsolate(); 631 Isolate* isolate = scope_info->GetIsolate();
632 for (int var = 0; var < scope_info->ContextLocalCount(); var++) { 632 for (int var = 0; var < scope_info->ContextLocalCount(); var++) {
633 Handle<String> name(scope_info->ContextLocalName(var)); 633 Handle<String> name(scope_info->ContextLocalName(var));
634 VariableMode mode = scope_info->ContextLocalMode(var); 634 VariableMode mode = scope_info->ContextLocalMode(var);
635 ScriptContextTable::LookupResult lookup; 635 ScriptContextTable::LookupResult lookup;
636 if (ScriptContextTable::Lookup(script_context, name, &lookup)) { 636 if (ScriptContextTable::Lookup(script_context, name, &lookup)) {
637 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) { 637 if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode)) {
638 return ThrowRedeclarationError(isolate, name); 638 return ThrowRedeclarationError(isolate, name);
639 } 639 }
640 } 640 }
641 641
642 if (IsLexicalVariableMode(mode)) { 642 if (IsLexicalVariableMode(mode)) {
643 LookupIterator it(global_object, name, 643 LookupIterator it(global_object, name,
644 LookupIterator::HIDDEN_SKIP_INTERCEPTOR); 644 LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
645 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it); 645 Maybe<PropertyAttributes> maybe = JSReceiver::GetPropertyAttributes(&it);
646 if (!maybe.IsJust()) return isolate->heap()->exception(); 646 if (!maybe.IsJust()) return isolate->heap()->exception();
647 if ((maybe.FromJust() & DONT_DELETE) != 0) { 647 if ((maybe.FromJust() & DONT_DELETE) != 0) {
648 return ThrowRedeclarationError(isolate, name); 648 return ThrowRedeclarationError(isolate, name);
649 } 649 }
650 650
651 GlobalObject::InvalidatePropertyCell(global_object, name); 651 JSGlobalObject::InvalidatePropertyCell(global_object, name);
652 } 652 }
653 } 653 }
654 return isolate->heap()->undefined_value(); 654 return isolate->heap()->undefined_value();
655 } 655 }
656 656
657 657
658 RUNTIME_FUNCTION(Runtime_NewScriptContext) { 658 RUNTIME_FUNCTION(Runtime_NewScriptContext) {
659 HandleScope scope(isolate); 659 HandleScope scope(isolate);
660 DCHECK(args.length() == 2); 660 DCHECK(args.length() == 2);
661 661
662 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 662 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
663 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); 663 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1);
664 Handle<GlobalObject> global_object(function->context()->global_object()); 664 Handle<JSGlobalObject> global_object(function->context()->global_object());
665 Handle<Context> native_context(global_object->native_context()); 665 Handle<Context> native_context(global_object->native_context());
666 Handle<ScriptContextTable> script_context_table( 666 Handle<ScriptContextTable> script_context_table(
667 native_context->script_context_table()); 667 native_context->script_context_table());
668 668
669 Object* name_clash_result = 669 Object* name_clash_result =
670 FindNameClash(scope_info, global_object, script_context_table); 670 FindNameClash(scope_info, global_object, script_context_table);
671 if (isolate->has_pending_exception()) return name_clash_result; 671 if (isolate->has_pending_exception()) return name_clash_result;
672 672
673 // Script contexts have a canonical empty function as their closure, not the 673 // Script contexts have a canonical empty function as their closure, not the
674 // anonymous closure containing the global code. See 674 // anonymous closure containing the global code. See
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 // (respecting DONT_DELETE). 903 // (respecting DONT_DELETE).
904 Handle<JSObject> object = Handle<JSObject>::cast(holder); 904 Handle<JSObject> object = Handle<JSObject>::cast(holder);
905 Handle<Object> result; 905 Handle<Object> result;
906 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, 906 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result,
907 JSReceiver::DeleteProperty(object, name)); 907 JSReceiver::DeleteProperty(object, name));
908 return *result; 908 return *result;
909 } 909 }
910 910
911 911
912 static Object* ComputeReceiverForNonGlobal(Isolate* isolate, JSObject* holder) { 912 static Object* ComputeReceiverForNonGlobal(Isolate* isolate, JSObject* holder) {
913 DCHECK(!holder->IsGlobalObject()); 913 DCHECK(!holder->IsJSGlobalObject());
914 914
915 // If the holder isn't a context extension object, we just return it 915 // If the holder isn't a context extension object, we just return it
916 // as the receiver. This allows arguments objects to be used as 916 // as the receiver. This allows arguments objects to be used as
917 // receivers, but only if they are put in the context scope chain 917 // receivers, but only if they are put in the context scope chain
918 // explicitly via a with-statement. 918 // explicitly via a with-statement.
919 if (holder->map()->instance_type() != JS_CONTEXT_EXTENSION_OBJECT_TYPE) { 919 if (holder->map()->instance_type() != JS_CONTEXT_EXTENSION_OBJECT_TYPE) {
920 return holder; 920 return holder;
921 } 921 }
922 // Fall back to using the global object as the implicit receiver if 922 // Fall back to using the global object as the implicit receiver if
923 // the property turns out to be a local variable allocated in a 923 // the property turns out to be a local variable allocated in a
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 } 981 }
982 } 982 }
983 983
984 // Otherwise, if the slot was found the holder is a context extension 984 // Otherwise, if the slot was found the holder is a context extension
985 // object, subject of a with, or a global object. We read the named 985 // object, subject of a with, or a global object. We read the named
986 // property from it. 986 // property from it.
987 if (!holder.is_null()) { 987 if (!holder.is_null()) {
988 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder); 988 Handle<JSReceiver> object = Handle<JSReceiver>::cast(holder);
989 // GetProperty below can cause GC. 989 // GetProperty below can cause GC.
990 Handle<Object> receiver_handle( 990 Handle<Object> receiver_handle(
991 object->IsGlobalObject() 991 object->IsJSGlobalObject()
992 ? Object::cast(isolate->heap()->undefined_value()) 992 ? Object::cast(isolate->heap()->undefined_value())
993 : object->IsJSProxy() ? static_cast<Object*>(*object) 993 : object->IsJSProxy() ? static_cast<Object*>(*object)
994 : ComputeReceiverForNonGlobal( 994 : ComputeReceiverForNonGlobal(
995 isolate, JSObject::cast(*object)), 995 isolate, JSObject::cast(*object)),
996 isolate); 996 isolate);
997 997
998 // No need to unhole the value here. This is taken care of by the 998 // No need to unhole the value here. This is taken care of by the
999 // GetProperty function. 999 // GetProperty function.
1000 Handle<Object> value; 1000 Handle<Object> value;
1001 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 1001 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 1166
1167 // Lookup in the initial Object.prototype object. 1167 // Lookup in the initial Object.prototype object.
1168 Handle<Object> result; 1168 Handle<Object> result;
1169 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1169 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1170 isolate, result, 1170 isolate, result,
1171 Object::GetProperty(isolate->initial_object_prototype(), key)); 1171 Object::GetProperty(isolate->initial_object_prototype(), key));
1172 return *result; 1172 return *result;
1173 } 1173 }
1174 } // namespace internal 1174 } // namespace internal
1175 } // namespace v8 1175 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | src/snapshot/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698