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

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

Issue 894683003: Introduce LanguageMode, drop StrictMode. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased (w/ conflicts) Created 5 years, 10 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-object.cc ('k') | src/runtime/runtime-utils.h » ('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/runtime/runtime-utils.h" 10 #include "src/runtime/runtime-utils.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 HandleScope scope(isolate); 146 HandleScope scope(isolate);
147 // args[0] == name 147 // args[0] == name
148 // args[1] == language_mode 148 // args[1] == language_mode
149 // args[2] == value (optional) 149 // args[2] == value (optional)
150 150
151 // Determine if we need to assign to the variable if it already 151 // Determine if we need to assign to the variable if it already
152 // exists (based on the number of arguments). 152 // exists (based on the number of arguments).
153 RUNTIME_ASSERT(args.length() == 3); 153 RUNTIME_ASSERT(args.length() == 3);
154 154
155 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); 155 CONVERT_ARG_HANDLE_CHECKED(String, name, 0);
156 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 1); 156 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 1);
157 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); 157 CONVERT_ARG_HANDLE_CHECKED(Object, value, 2);
158 158
159 Handle<GlobalObject> global(isolate->context()->global_object()); 159 Handle<GlobalObject> global(isolate->context()->global_object());
160 Handle<Object> result; 160 Handle<Object> result;
161 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 161 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
162 isolate, result, Object::SetProperty(global, name, value, strict_mode)); 162 isolate, result, Object::SetProperty(global, name, value, language_mode));
163 return *result; 163 return *result;
164 } 164 }
165 165
166 166
167 RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) { 167 RUNTIME_FUNCTION(Runtime_InitializeConstGlobal) {
168 HandleScope handle_scope(isolate); 168 HandleScope handle_scope(isolate);
169 // All constants are declared with an initial value. The name 169 // All constants are declared with an initial value. The name
170 // of the constant is the first argument and the initial value 170 // of the constant is the first argument and the initial value
171 // is the second. 171 // is the second.
172 RUNTIME_ASSERT(args.length() == 2); 172 RUNTIME_ASSERT(args.length() == 2);
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); 470 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0);
471 JavaScriptFrameIterator it(isolate); 471 JavaScriptFrameIterator it(isolate);
472 472
473 // Find the frame that holds the actual arguments passed to the function. 473 // Find the frame that holds the actual arguments passed to the function.
474 it.AdvanceToArgumentsFrame(); 474 it.AdvanceToArgumentsFrame();
475 JavaScriptFrame* frame = it.frame(); 475 JavaScriptFrame* frame = it.frame();
476 476
477 // Determine parameter location on the stack and dispatch on language mode. 477 // Determine parameter location on the stack and dispatch on language mode.
478 int argument_count = frame->GetArgumentsLength(); 478 int argument_count = frame->GetArgumentsLength();
479 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1)); 479 Object** parameters = reinterpret_cast<Object**>(frame->GetParameterSlot(-1));
480 return callee->shared()->strict_mode() == STRICT 480 return is_strict(callee->shared()->language_mode())
481 ? *NewStrictArguments(isolate, callee, parameters, argument_count) 481 ? *NewStrictArguments(isolate, callee, parameters, argument_count)
482 : *NewSloppyArguments(isolate, callee, parameters, argument_count); 482 : *NewSloppyArguments(isolate, callee, parameters, argument_count);
483 } 483 }
484 484
485 485
486 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) { 486 RUNTIME_FUNCTION(Runtime_NewSloppyArguments) {
487 HandleScope scope(isolate); 487 HandleScope scope(isolate);
488 DCHECK(args.length() == 3); 488 DCHECK(args.length() == 3);
489 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0); 489 CONVERT_ARG_HANDLE_CHECKED(JSFunction, callee, 0);
490 Object** parameters = reinterpret_cast<Object**>(args[1]); 490 Object** parameters = reinterpret_cast<Object**>(args[1]);
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 } 942 }
943 943
944 944
945 RUNTIME_FUNCTION(Runtime_StoreLookupSlot) { 945 RUNTIME_FUNCTION(Runtime_StoreLookupSlot) {
946 HandleScope scope(isolate); 946 HandleScope scope(isolate);
947 DCHECK(args.length() == 4); 947 DCHECK(args.length() == 4);
948 948
949 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0); 949 CONVERT_ARG_HANDLE_CHECKED(Object, value, 0);
950 CONVERT_ARG_HANDLE_CHECKED(Context, context, 1); 950 CONVERT_ARG_HANDLE_CHECKED(Context, context, 1);
951 CONVERT_ARG_HANDLE_CHECKED(String, name, 2); 951 CONVERT_ARG_HANDLE_CHECKED(String, name, 2);
952 CONVERT_STRICT_MODE_ARG_CHECKED(strict_mode, 3); 952 CONVERT_LANGUAGE_MODE_ARG_CHECKED(language_mode, 3);
953 953
954 int index; 954 int index;
955 PropertyAttributes attributes; 955 PropertyAttributes attributes;
956 ContextLookupFlags flags = FOLLOW_CHAINS; 956 ContextLookupFlags flags = FOLLOW_CHAINS;
957 BindingFlags binding_flags; 957 BindingFlags binding_flags;
958 Handle<Object> holder = 958 Handle<Object> holder =
959 context->Lookup(name, flags, &index, &attributes, &binding_flags); 959 context->Lookup(name, flags, &index, &attributes, &binding_flags);
960 // In case of JSProxy, an exception might have been thrown. 960 // In case of JSProxy, an exception might have been thrown.
961 if (isolate->has_pending_exception()) return isolate->heap()->exception(); 961 if (isolate->has_pending_exception()) return isolate->heap()->exception();
962 962
963 // The property was found in a context slot. 963 // The property was found in a context slot.
964 if (index >= 0) { 964 if (index >= 0) {
965 if ((attributes & READ_ONLY) == 0) { 965 if ((attributes & READ_ONLY) == 0) {
966 Handle<Context>::cast(holder)->set(index, *value); 966 Handle<Context>::cast(holder)->set(index, *value);
967 } else if (strict_mode == STRICT) { 967 } else if (is_strict(language_mode)) {
968 // Setting read only property in strict mode. 968 // Setting read only property in strict mode.
969 THROW_NEW_ERROR_RETURN_FAILURE( 969 THROW_NEW_ERROR_RETURN_FAILURE(
970 isolate, 970 isolate,
971 NewTypeError("strict_cannot_assign", HandleVector(&name, 1))); 971 NewTypeError("strict_cannot_assign", HandleVector(&name, 1)));
972 } 972 }
973 return *value; 973 return *value;
974 } 974 }
975 975
976 // Slow case: The property is not in a context slot. It is either in a 976 // Slow case: The property is not in a context slot. It is either in a
977 // context extension object, a property of the subject of a with, or a 977 // context extension object, a property of the subject of a with, or a
978 // property of the global object. 978 // property of the global object.
979 Handle<JSReceiver> object; 979 Handle<JSReceiver> object;
980 if (attributes != ABSENT) { 980 if (attributes != ABSENT) {
981 // The property exists on the holder. 981 // The property exists on the holder.
982 object = Handle<JSReceiver>::cast(holder); 982 object = Handle<JSReceiver>::cast(holder);
983 } else if (strict_mode == STRICT) { 983 } else if (is_strict(language_mode)) {
984 // If absent in strict mode: throw. 984 // If absent in strict mode: throw.
985 THROW_NEW_ERROR_RETURN_FAILURE( 985 THROW_NEW_ERROR_RETURN_FAILURE(
986 isolate, NewReferenceError("not_defined", HandleVector(&name, 1))); 986 isolate, NewReferenceError("not_defined", HandleVector(&name, 1)));
987 } else { 987 } else {
988 // If absent in sloppy mode: add the property to the global object. 988 // If absent in sloppy mode: add the property to the global object.
989 object = Handle<JSReceiver>(context->global_object()); 989 object = Handle<JSReceiver>(context->global_object());
990 } 990 }
991 991
992 RETURN_FAILURE_ON_EXCEPTION( 992 RETURN_FAILURE_ON_EXCEPTION(
993 isolate, Object::SetProperty(object, name, value, strict_mode)); 993 isolate, Object::SetProperty(object, name, value, language_mode));
994 994
995 return *value; 995 return *value;
996 } 996 }
997 997
998 998
999 RUNTIME_FUNCTION(Runtime_GetArgumentsProperty) { 999 RUNTIME_FUNCTION(Runtime_GetArgumentsProperty) {
1000 SealHandleScope shs(isolate); 1000 SealHandleScope shs(isolate);
1001 DCHECK(args.length() == 1); 1001 DCHECK(args.length() == 1);
1002 CONVERT_ARG_HANDLE_CHECKED(Object, raw_key, 0); 1002 CONVERT_ARG_HANDLE_CHECKED(Object, raw_key, 0);
1003 1003
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 return *result; 1050 return *result;
1051 } 1051 }
1052 } 1052 }
1053 1053
1054 // Handle special arguments properties. 1054 // Handle special arguments properties.
1055 if (String::Equals(isolate->factory()->length_string(), key)) { 1055 if (String::Equals(isolate->factory()->length_string(), key)) {
1056 return Smi::FromInt(n); 1056 return Smi::FromInt(n);
1057 } 1057 }
1058 if (String::Equals(isolate->factory()->callee_string(), key)) { 1058 if (String::Equals(isolate->factory()->callee_string(), key)) {
1059 JSFunction* function = frame->function(); 1059 JSFunction* function = frame->function();
1060 if (function->shared()->strict_mode() == STRICT) { 1060 if (is_strict(function->shared()->language_mode())) {
1061 THROW_NEW_ERROR_RETURN_FAILURE( 1061 THROW_NEW_ERROR_RETURN_FAILURE(
1062 isolate, NewTypeError("strict_arguments_callee", 1062 isolate, NewTypeError("strict_arguments_callee",
1063 HandleVector<Object>(NULL, 0))); 1063 HandleVector<Object>(NULL, 0)));
1064 } 1064 }
1065 return function; 1065 return function;
1066 } 1066 }
1067 1067
1068 // Lookup in the initial Object.prototype object. 1068 // Lookup in the initial Object.prototype object.
1069 Handle<Object> result; 1069 Handle<Object> result;
1070 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1070 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
(...skipping 11 matching lines...) Expand all
1082 return Smi::FromInt(frame->GetArgumentsLength()); 1082 return Smi::FromInt(frame->GetArgumentsLength());
1083 } 1083 }
1084 1084
1085 1085
1086 RUNTIME_FUNCTION(RuntimeReference_Arguments) { 1086 RUNTIME_FUNCTION(RuntimeReference_Arguments) {
1087 SealHandleScope shs(isolate); 1087 SealHandleScope shs(isolate);
1088 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate); 1088 return __RT_impl_Runtime_GetArgumentsProperty(args, isolate);
1089 } 1089 }
1090 } 1090 }
1091 } // namespace v8::internal 1091 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | src/runtime/runtime-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698