| 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/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 MessageTemplate::Template template_index, | 1147 MessageTemplate::Template template_index, |
| 1148 Handle<Object> arg0, Handle<Object> arg1, | 1148 Handle<Object> arg0, Handle<Object> arg1, |
| 1149 Handle<Object> arg2) { | 1149 Handle<Object> arg2) { |
| 1150 HandleScope scope(isolate()); | 1150 HandleScope scope(isolate()); |
| 1151 if (isolate()->bootstrapper()->IsActive()) { | 1151 if (isolate()->bootstrapper()->IsActive()) { |
| 1152 // During bootstrapping we cannot construct error objects. | 1152 // During bootstrapping we cannot construct error objects. |
| 1153 return scope.CloseAndEscape(NewStringFromAsciiChecked( | 1153 return scope.CloseAndEscape(NewStringFromAsciiChecked( |
| 1154 MessageTemplate::TemplateString(template_index))); | 1154 MessageTemplate::TemplateString(template_index))); |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 Handle<JSFunction> fun = isolate()->make_error_function(); | |
| 1158 Handle<Object> message_type(Smi::FromInt(template_index), isolate()); | |
| 1159 if (arg0.is_null()) arg0 = undefined_value(); | 1157 if (arg0.is_null()) arg0 = undefined_value(); |
| 1160 if (arg1.is_null()) arg1 = undefined_value(); | 1158 if (arg1.is_null()) arg1 = undefined_value(); |
| 1161 if (arg2.is_null()) arg2 = undefined_value(); | 1159 if (arg2.is_null()) arg2 = undefined_value(); |
| 1162 Handle<Object> argv[] = {constructor, message_type, arg0, arg1, arg2}; | |
| 1163 | 1160 |
| 1164 // Invoke the JavaScript factory method. If an exception is thrown while | |
| 1165 // running the factory method, use the exception as the result. | |
| 1166 Handle<Object> result; | 1161 Handle<Object> result; |
| 1167 MaybeHandle<Object> exception; | 1162 if (!ErrorUtils::MakeGenericError(isolate(), constructor, template_index, |
| 1168 if (!Execution::TryCall(isolate(), fun, undefined_value(), arraysize(argv), | 1163 arg0, arg1, arg2, SKIP_NONE) |
| 1169 argv, &exception) | |
| 1170 .ToHandle(&result)) { | 1164 .ToHandle(&result)) { |
| 1171 Handle<Object> exception_obj; | 1165 // If an exception is thrown while |
| 1172 if (exception.ToHandle(&exception_obj)) { | 1166 // running the factory method, use the exception as the result. |
| 1173 result = exception_obj; | 1167 DCHECK(isolate()->has_pending_exception()); |
| 1174 } else { | 1168 result = handle(isolate()->pending_exception(), isolate()); |
| 1175 result = undefined_value(); | 1169 isolate()->clear_pending_exception(); |
| 1176 } | |
| 1177 } | 1170 } |
| 1171 |
| 1178 return scope.CloseAndEscape(result); | 1172 return scope.CloseAndEscape(result); |
| 1179 } | 1173 } |
| 1180 | 1174 |
| 1181 | 1175 |
| 1182 Handle<Object> Factory::NewError(Handle<JSFunction> constructor, | 1176 Handle<Object> Factory::NewError(Handle<JSFunction> constructor, |
| 1183 Handle<String> message) { | 1177 Handle<String> message) { |
| 1184 Handle<Object> argv[] = { message }; | 1178 Handle<Object> argv[] = { message }; |
| 1185 | 1179 |
| 1186 // Invoke the JavaScript factory method. If an exception is thrown while | 1180 // Invoke the JavaScript factory method. If an exception is thrown while |
| 1187 // running the factory method, use the exception as the result. | 1181 // running the factory method, use the exception as the result. |
| (...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2502 Handle<AccessorInfo> prototype = | 2496 Handle<AccessorInfo> prototype = |
| 2503 Accessors::FunctionPrototypeInfo(isolate(), attribs); | 2497 Accessors::FunctionPrototypeInfo(isolate(), attribs); |
| 2504 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), | 2498 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
| 2505 prototype, attribs); | 2499 prototype, attribs); |
| 2506 map->AppendDescriptor(&d); | 2500 map->AppendDescriptor(&d); |
| 2507 } | 2501 } |
| 2508 } | 2502 } |
| 2509 | 2503 |
| 2510 } // namespace internal | 2504 } // namespace internal |
| 2511 } // namespace v8 | 2505 } // namespace v8 |
| OLD | NEW |