| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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/api.h" | 7 #include "src/api.h" |
| 8 #include "src/execution.h" | 8 #include "src/execution.h" |
| 9 #include "src/messages.h" | 9 #include "src/messages.h" |
| 10 #include "src/string-builder.h" | 10 #include "src/string-builder.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 Isolate::ExceptionScope exception_scope(isolate); | 74 Isolate::ExceptionScope exception_scope(isolate); |
| 75 isolate->clear_pending_exception(); | 75 isolate->clear_pending_exception(); |
| 76 isolate->set_external_caught_exception(false); | 76 isolate->set_external_caught_exception(false); |
| 77 | 77 |
| 78 // Turn the exception on the message into a string if it is an object. | 78 // Turn the exception on the message into a string if it is an object. |
| 79 if (message->argument()->IsJSObject()) { | 79 if (message->argument()->IsJSObject()) { |
| 80 HandleScope scope(isolate); | 80 HandleScope scope(isolate); |
| 81 Handle<Object> argument(message->argument(), isolate); | 81 Handle<Object> argument(message->argument(), isolate); |
| 82 Handle<Object> args[] = {argument}; | 82 Handle<Object> args[] = {argument}; |
| 83 MaybeHandle<Object> maybe_stringified = Execution::TryCall( | 83 MaybeHandle<Object> maybe_stringified = Execution::TryCall( |
| 84 isolate->to_detail_string_fun(), isolate->js_builtins_object(), | 84 isolate->to_detail_string_fun(), isolate->factory()->undefined_value(), |
| 85 arraysize(args), args); | 85 arraysize(args), args); |
| 86 Handle<Object> stringified; | 86 Handle<Object> stringified; |
| 87 if (!maybe_stringified.ToHandle(&stringified)) { | 87 if (!maybe_stringified.ToHandle(&stringified)) { |
| 88 stringified = isolate->factory()->NewStringFromAsciiChecked("exception"); | 88 stringified = isolate->factory()->NewStringFromAsciiChecked("exception"); |
| 89 } | 89 } |
| 90 message->set_argument(*stringified); | 90 message->set_argument(*stringified); |
| 91 } | 91 } |
| 92 | 92 |
| 93 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); | 93 v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message); |
| 94 v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception); | 94 v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 290 |
| 291 | 291 |
| 292 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, | 292 Handle<String> MessageTemplate::FormatMessage(Isolate* isolate, |
| 293 int template_index, | 293 int template_index, |
| 294 Handle<Object> arg) { | 294 Handle<Object> arg) { |
| 295 Factory* factory = isolate->factory(); | 295 Factory* factory = isolate->factory(); |
| 296 Handle<String> result_string; | 296 Handle<String> result_string; |
| 297 if (arg->IsString()) { | 297 if (arg->IsString()) { |
| 298 result_string = Handle<String>::cast(arg); | 298 result_string = Handle<String>::cast(arg); |
| 299 } else { | 299 } else { |
| 300 Handle<String> fmt_str = factory->InternalizeOneByteString( | 300 Handle<JSFunction> fun = isolate->no_side_effect_to_string_fun(); |
| 301 STATIC_CHAR_VECTOR("$noSideEffectToString")); | |
| 302 Handle<JSFunction> fun = Handle<JSFunction>::cast( | |
| 303 Object::GetProperty(isolate->js_builtins_object(), fmt_str) | |
| 304 .ToHandleChecked()); | |
| 305 | 301 |
| 306 MaybeHandle<Object> maybe_result = | 302 MaybeHandle<Object> maybe_result = |
| 307 Execution::TryCall(fun, factory->undefined_value(), 1, &arg); | 303 Execution::TryCall(fun, factory->undefined_value(), 1, &arg); |
| 308 Handle<Object> result; | 304 Handle<Object> result; |
| 309 if (!maybe_result.ToHandle(&result) || !result->IsString()) { | 305 if (!maybe_result.ToHandle(&result) || !result->IsString()) { |
| 310 return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>")); | 306 return factory->InternalizeOneByteString(STATIC_CHAR_VECTOR("<error>")); |
| 311 } | 307 } |
| 312 result_string = Handle<String>::cast(result); | 308 result_string = Handle<String>::cast(result); |
| 313 } | 309 } |
| 314 MaybeHandle<String> maybe_result_string = MessageTemplate::FormatMessage( | 310 MaybeHandle<String> maybe_result_string = MessageTemplate::FormatMessage( |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 if (obj->IsUndefined()) return default_value; | 450 if (obj->IsUndefined()) return default_value; |
| 455 if (!obj->IsString()) { | 451 if (!obj->IsString()) { |
| 456 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, Execution::ToString(isolate, obj), | 452 ASSIGN_RETURN_ON_EXCEPTION(isolate, obj, Execution::ToString(isolate, obj), |
| 457 String); | 453 String); |
| 458 } | 454 } |
| 459 return Handle<String>::cast(obj); | 455 return Handle<String>::cast(obj); |
| 460 } | 456 } |
| 461 | 457 |
| 462 } // namespace internal | 458 } // namespace internal |
| 463 } // namespace v8 | 459 } // namespace v8 |
| OLD | NEW |