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/factory.h" | 5 #include "src/factory.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/conversions.h" | 8 #include "src/conversions.h" |
9 #include "src/isolate-inl.h" | 9 #include "src/isolate-inl.h" |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 const int kBufferSize = 1000; | 1132 const int kBufferSize = 1000; |
1133 char buffer[kBufferSize]; | 1133 char buffer[kBufferSize]; |
1134 size_t space = kBufferSize; | 1134 size_t space = kBufferSize; |
1135 char* p = &buffer[0]; | 1135 char* p = &buffer[0]; |
1136 | 1136 |
1137 Vector<char> v(buffer, kBufferSize); | 1137 Vector<char> v(buffer, kBufferSize); |
1138 StrNCpy(v, message, space); | 1138 StrNCpy(v, message, space); |
1139 space -= Min(space, strlen(message)); | 1139 space -= Min(space, strlen(message)); |
1140 p = &buffer[kBufferSize] - space; | 1140 p = &buffer[kBufferSize] - space; |
1141 | 1141 |
1142 for (unsigned i = 0; i < ARRAY_SIZE(args); i++) { | 1142 for (int i = 0; i < Smi::cast(args->length())->value(); i++) { |
1143 if (space > 0) { | 1143 if (space > 0) { |
1144 *p++ = ' '; | 1144 *p++ = ' '; |
1145 space--; | 1145 space--; |
1146 if (space > 0) { | 1146 if (space > 0) { |
1147 Handle<String> arg_str = Handle<String>::cast( | 1147 Handle<String> arg_str = Handle<String>::cast( |
1148 Object::GetElement(isolate(), args, i).ToHandleChecked()); | 1148 Object::GetElement(isolate(), args, i).ToHandleChecked()); |
1149 SmartArrayPointer<char> arg = arg_str->ToCString(); | 1149 SmartArrayPointer<char> arg = arg_str->ToCString(); |
1150 Vector<char> v2(p, static_cast<int>(space)); | 1150 Vector<char> v2(p, static_cast<int>(space)); |
1151 StrNCpy(v2, arg.get(), space); | 1151 StrNCpy(v2, arg.get(), space); |
1152 space -= Min(space, strlen(arg.get())); | 1152 space -= Min(space, strlen(arg.get())); |
(...skipping 24 matching lines...) Expand all Loading... |
1177 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); | 1177 Handle<JSFunction> fun = Handle<JSFunction>::cast(fun_obj); |
1178 Handle<Object> message_obj = InternalizeUtf8String(message); | 1178 Handle<Object> message_obj = InternalizeUtf8String(message); |
1179 Handle<Object> argv[] = { message_obj, args }; | 1179 Handle<Object> argv[] = { message_obj, args }; |
1180 | 1180 |
1181 // Invoke the JavaScript factory method. If an exception is thrown while | 1181 // Invoke the JavaScript factory method. If an exception is thrown while |
1182 // running the factory method, use the exception as the result. | 1182 // running the factory method, use the exception as the result. |
1183 Handle<Object> result; | 1183 Handle<Object> result; |
1184 Handle<Object> exception; | 1184 Handle<Object> exception; |
1185 if (!Execution::TryCall(fun, | 1185 if (!Execution::TryCall(fun, |
1186 isolate()->js_builtins_object(), | 1186 isolate()->js_builtins_object(), |
1187 ARRAY_SIZE(argv), | 1187 arraysize(argv), |
1188 argv, | 1188 argv, |
1189 &exception).ToHandle(&result)) { | 1189 &exception).ToHandle(&result)) { |
1190 return exception; | 1190 return exception; |
1191 } | 1191 } |
1192 return result; | 1192 return result; |
1193 } | 1193 } |
1194 | 1194 |
1195 | 1195 |
1196 Handle<Object> Factory::NewError(Handle<String> message) { | 1196 Handle<Object> Factory::NewError(Handle<String> message) { |
1197 return NewError("$Error", message); | 1197 return NewError("$Error", message); |
1198 } | 1198 } |
1199 | 1199 |
1200 | 1200 |
1201 Handle<Object> Factory::NewError(const char* constructor, | 1201 Handle<Object> Factory::NewError(const char* constructor, |
1202 Handle<String> message) { | 1202 Handle<String> message) { |
1203 Handle<String> constr = InternalizeUtf8String(constructor); | 1203 Handle<String> constr = InternalizeUtf8String(constructor); |
1204 Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty( | 1204 Handle<JSFunction> fun = Handle<JSFunction>::cast(Object::GetProperty( |
1205 isolate()->js_builtins_object(), constr).ToHandleChecked()); | 1205 isolate()->js_builtins_object(), constr).ToHandleChecked()); |
1206 Handle<Object> argv[] = { message }; | 1206 Handle<Object> argv[] = { message }; |
1207 | 1207 |
1208 // Invoke the JavaScript factory method. If an exception is thrown while | 1208 // Invoke the JavaScript factory method. If an exception is thrown while |
1209 // running the factory method, use the exception as the result. | 1209 // running the factory method, use the exception as the result. |
1210 Handle<Object> result; | 1210 Handle<Object> result; |
1211 Handle<Object> exception; | 1211 Handle<Object> exception; |
1212 if (!Execution::TryCall(fun, | 1212 if (!Execution::TryCall(fun, |
1213 isolate()->js_builtins_object(), | 1213 isolate()->js_builtins_object(), |
1214 ARRAY_SIZE(argv), | 1214 arraysize(argv), |
1215 argv, | 1215 argv, |
1216 &exception).ToHandle(&result)) { | 1216 &exception).ToHandle(&result)) { |
1217 return exception; | 1217 return exception; |
1218 } | 1218 } |
1219 return result; | 1219 return result; |
1220 } | 1220 } |
1221 | 1221 |
1222 | 1222 |
1223 void Factory::InitializeFunction(Handle<JSFunction> function, | 1223 void Factory::InitializeFunction(Handle<JSFunction> function, |
1224 Handle<SharedFunctionInfo> info, | 1224 Handle<SharedFunctionInfo> info, |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2032 | 2032 |
2033 Handle<String> Factory::NumberToString(Handle<Object> number, | 2033 Handle<String> Factory::NumberToString(Handle<Object> number, |
2034 bool check_number_string_cache) { | 2034 bool check_number_string_cache) { |
2035 isolate()->counters()->number_to_string_runtime()->Increment(); | 2035 isolate()->counters()->number_to_string_runtime()->Increment(); |
2036 if (check_number_string_cache) { | 2036 if (check_number_string_cache) { |
2037 Handle<Object> cached = GetNumberStringCache(number); | 2037 Handle<Object> cached = GetNumberStringCache(number); |
2038 if (!cached->IsUndefined()) return Handle<String>::cast(cached); | 2038 if (!cached->IsUndefined()) return Handle<String>::cast(cached); |
2039 } | 2039 } |
2040 | 2040 |
2041 char arr[100]; | 2041 char arr[100]; |
2042 Vector<char> buffer(arr, ARRAY_SIZE(arr)); | 2042 Vector<char> buffer(arr, arraysize(arr)); |
2043 const char* str; | 2043 const char* str; |
2044 if (number->IsSmi()) { | 2044 if (number->IsSmi()) { |
2045 int num = Handle<Smi>::cast(number)->value(); | 2045 int num = Handle<Smi>::cast(number)->value(); |
2046 str = IntToCString(num, buffer); | 2046 str = IntToCString(num, buffer); |
2047 } else { | 2047 } else { |
2048 double num = Handle<HeapNumber>::cast(number)->value(); | 2048 double num = Handle<HeapNumber>::cast(number)->value(); |
2049 str = DoubleToCString(num, buffer); | 2049 str = DoubleToCString(num, buffer); |
2050 } | 2050 } |
2051 | 2051 |
2052 // We tenure the allocated string since it is referenced from the | 2052 // We tenure the allocated string since it is referenced from the |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2379 return Handle<Object>::null(); | 2379 return Handle<Object>::null(); |
2380 } | 2380 } |
2381 | 2381 |
2382 | 2382 |
2383 Handle<Object> Factory::ToBoolean(bool value) { | 2383 Handle<Object> Factory::ToBoolean(bool value) { |
2384 return value ? true_value() : false_value(); | 2384 return value ? true_value() : false_value(); |
2385 } | 2385 } |
2386 | 2386 |
2387 | 2387 |
2388 } } // namespace v8::internal | 2388 } } // namespace v8::internal |
OLD | NEW |