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/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 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 } | 1039 } |
1040 | 1040 |
1041 RETURN_FAILURE_ON_EXCEPTION( | 1041 RETURN_FAILURE_ON_EXCEPTION( |
1042 isolate, Object::SetProperty(object, name, value, language_mode)); | 1042 isolate, Object::SetProperty(object, name, value, language_mode)); |
1043 | 1043 |
1044 return *value; | 1044 return *value; |
1045 } | 1045 } |
1046 | 1046 |
1047 | 1047 |
1048 RUNTIME_FUNCTION(Runtime_ArgumentsLength) { | 1048 RUNTIME_FUNCTION(Runtime_ArgumentsLength) { |
1049 SealHandleScope shs(isolate); | 1049 HandleScope scope(isolate); |
1050 DCHECK(args.length() == 0); | 1050 DCHECK(args.length() == 0); |
1051 JavaScriptFrameIterator it(isolate); | 1051 int argument_count = 0; |
1052 JavaScriptFrame* frame = it.frame(); | 1052 Runtime::GetCallerArguments(isolate, 0, &argument_count); |
1053 return Smi::FromInt(frame->GetArgumentsLength()); | 1053 return Smi::FromInt(argument_count); |
1054 } | 1054 } |
1055 | 1055 |
1056 | 1056 |
1057 RUNTIME_FUNCTION(Runtime_Arguments) { | 1057 RUNTIME_FUNCTION(Runtime_Arguments) { |
1058 SealHandleScope shs(isolate); | 1058 HandleScope scope(isolate); |
1059 DCHECK(args.length() == 1); | 1059 DCHECK(args.length() == 1); |
1060 CONVERT_ARG_HANDLE_CHECKED(Object, raw_key, 0); | 1060 CONVERT_ARG_HANDLE_CHECKED(Object, raw_key, 0); |
1061 | 1061 |
1062 // Compute the frame holding the arguments. | 1062 // Determine the actual arguments passed to the function. |
1063 JavaScriptFrameIterator it(isolate); | 1063 int argument_count_signed = 0; |
1064 it.AdvanceToArgumentsFrame(); | 1064 base::SmartArrayPointer<Handle<Object>> arguments = |
1065 JavaScriptFrame* frame = it.frame(); | 1065 Runtime::GetCallerArguments(isolate, 0, &argument_count_signed); |
1066 | 1066 const uint32_t argument_count = argument_count_signed; |
1067 // Get the actual number of provided arguments. | |
1068 const uint32_t n = frame->ComputeParametersCount(); | |
1069 | 1067 |
1070 // Try to convert the key to an index. If successful and within | 1068 // Try to convert the key to an index. If successful and within |
1071 // index return the the argument from the frame. | 1069 // index return the the argument from the frame. |
1072 uint32_t index = 0; | 1070 uint32_t index = 0; |
1073 if (raw_key->ToArrayIndex(&index) && index < n) { | 1071 if (raw_key->ToArrayIndex(&index) && index < argument_count) { |
1074 return frame->GetParameter(index); | 1072 return *arguments[index]; |
1075 } | 1073 } |
1076 | 1074 |
1077 HandleScope scope(isolate); | |
1078 if (raw_key->IsSymbol()) { | 1075 if (raw_key->IsSymbol()) { |
1079 Handle<Symbol> symbol = Handle<Symbol>::cast(raw_key); | 1076 Handle<Symbol> symbol = Handle<Symbol>::cast(raw_key); |
1080 if (Name::Equals(symbol, isolate->factory()->iterator_symbol())) { | 1077 if (Name::Equals(symbol, isolate->factory()->iterator_symbol())) { |
1081 return isolate->native_context()->array_values_iterator(); | 1078 return isolate->native_context()->array_values_iterator(); |
1082 } | 1079 } |
1083 // Lookup in the initial Object.prototype object. | 1080 // Lookup in the initial Object.prototype object. |
1084 Handle<Object> result; | 1081 Handle<Object> result; |
1085 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1082 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1086 isolate, result, | 1083 isolate, result, |
1087 Object::GetProperty(isolate->initial_object_prototype(), | 1084 Object::GetProperty(isolate->initial_object_prototype(), |
1088 Handle<Symbol>::cast(raw_key))); | 1085 Handle<Symbol>::cast(raw_key))); |
1089 return *result; | 1086 return *result; |
1090 } | 1087 } |
1091 | 1088 |
1092 // Convert the key to a string. | 1089 // Convert the key to a string. |
1093 Handle<Object> converted; | 1090 Handle<Object> converted; |
1094 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, converted, | 1091 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, converted, |
1095 Object::ToString(isolate, raw_key)); | 1092 Object::ToString(isolate, raw_key)); |
1096 Handle<String> key = Handle<String>::cast(converted); | 1093 Handle<String> key = Handle<String>::cast(converted); |
1097 | 1094 |
1098 // Try to convert the string key into an array index. | 1095 // Try to convert the string key into an array index. |
1099 if (key->AsArrayIndex(&index)) { | 1096 if (key->AsArrayIndex(&index)) { |
1100 if (index < n) { | 1097 if (index < argument_count) { |
1101 return frame->GetParameter(index); | 1098 return *arguments[index]; |
1102 } else { | 1099 } else { |
1103 Handle<Object> initial_prototype(isolate->initial_object_prototype()); | 1100 Handle<Object> initial_prototype(isolate->initial_object_prototype()); |
1104 Handle<Object> result; | 1101 Handle<Object> result; |
1105 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1102 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1106 isolate, result, | 1103 isolate, result, |
1107 Object::GetElement(isolate, initial_prototype, index)); | 1104 Object::GetElement(isolate, initial_prototype, index)); |
1108 return *result; | 1105 return *result; |
1109 } | 1106 } |
1110 } | 1107 } |
1111 | 1108 |
1112 // Handle special arguments properties. | 1109 // Handle special arguments properties. |
1113 if (String::Equals(isolate->factory()->length_string(), key)) { | 1110 if (String::Equals(isolate->factory()->length_string(), key)) { |
1114 return Smi::FromInt(n); | 1111 return Smi::FromInt(argument_count); |
1115 } | 1112 } |
1116 if (String::Equals(isolate->factory()->callee_string(), key)) { | 1113 if (String::Equals(isolate->factory()->callee_string(), key)) { |
1117 JSFunction* function = frame->function(); | 1114 JavaScriptFrameIterator it(isolate); |
| 1115 JSFunction* function = it.frame()->function(); |
1118 if (is_strict(function->shared()->language_mode())) { | 1116 if (is_strict(function->shared()->language_mode())) { |
1119 THROW_NEW_ERROR_RETURN_FAILURE( | 1117 THROW_NEW_ERROR_RETURN_FAILURE( |
1120 isolate, NewTypeError(MessageTemplate::kStrictPoisonPill)); | 1118 isolate, NewTypeError(MessageTemplate::kStrictPoisonPill)); |
1121 } | 1119 } |
1122 return function; | 1120 return function; |
1123 } | 1121 } |
1124 | 1122 |
1125 // Lookup in the initial Object.prototype object. | 1123 // Lookup in the initial Object.prototype object. |
1126 Handle<Object> result; | 1124 Handle<Object> result; |
1127 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 1125 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
1128 isolate, result, | 1126 isolate, result, |
1129 Object::GetProperty(isolate->initial_object_prototype(), key)); | 1127 Object::GetProperty(isolate->initial_object_prototype(), key)); |
1130 return *result; | 1128 return *result; |
1131 } | 1129 } |
1132 } // namespace internal | 1130 } // namespace internal |
1133 } // namespace v8 | 1131 } // namespace v8 |
OLD | NEW |