| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/arguments.h" | 9 #include "src/arguments.h" |
| 10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 Handle<Object> arg1 = (args.length() > 2) ? args.at<Object>(2) : undefined; | 110 Handle<Object> arg1 = (args.length() > 2) ? args.at<Object>(2) : undefined; |
| 111 Handle<Object> arg2 = (args.length() > 3) ? args.at<Object>(3) : undefined; | 111 Handle<Object> arg2 = (args.length() > 3) ? args.at<Object>(3) : undefined; |
| 112 | 112 |
| 113 MessageTemplate::Template message_id = | 113 MessageTemplate::Template message_id = |
| 114 static_cast<MessageTemplate::Template>(message_id_smi); | 114 static_cast<MessageTemplate::Template>(message_id_smi); |
| 115 | 115 |
| 116 THROW_NEW_ERROR_RETURN_FAILURE(isolate, | 116 THROW_NEW_ERROR_RETURN_FAILURE(isolate, |
| 117 NewTypeError(message_id, arg0, arg1, arg2)); | 117 NewTypeError(message_id, arg0, arg1, arg2)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 RUNTIME_FUNCTION(Runtime_ThrowWasmError) { | |
| 121 HandleScope scope(isolate); | |
| 122 DCHECK_EQ(2, args.length()); | |
| 123 CONVERT_SMI_ARG_CHECKED(message_id, 0); | |
| 124 CONVERT_SMI_ARG_CHECKED(byte_offset, 1); | |
| 125 Handle<Object> error_obj = isolate->factory()->NewWasmRuntimeError( | |
| 126 static_cast<MessageTemplate::Template>(message_id)); | |
| 127 | |
| 128 // For wasm traps, the byte offset (a.k.a source position) can not be | |
| 129 // determined from relocation info, since the explicit checks for traps | |
| 130 // converge in one singe block which calls this runtime function. | |
| 131 // We hence pass the byte offset explicitely, and patch it into the top-most | |
| 132 // frame (a wasm frame) on the collected stack trace. | |
| 133 // TODO(wasm): This implementation is temporary, see bug #5007: | |
| 134 // https://bugs.chromium.org/p/v8/issues/detail?id=5007 | |
| 135 Handle<JSObject> error = Handle<JSObject>::cast(error_obj); | |
| 136 Handle<Object> stack_trace_obj = JSReceiver::GetDataProperty( | |
| 137 error, isolate->factory()->stack_trace_symbol()); | |
| 138 // Patch the stack trace (array of <receiver, function, code, position>). | |
| 139 if (stack_trace_obj->IsJSArray()) { | |
| 140 Handle<FrameArray> stack_elements( | |
| 141 FrameArray::cast(JSArray::cast(*stack_trace_obj)->elements())); | |
| 142 DCHECK(stack_elements->Code(0)->kind() == AbstractCode::WASM_FUNCTION); | |
| 143 DCHECK(stack_elements->Offset(0)->value() >= 0); | |
| 144 stack_elements->SetOffset(0, Smi::FromInt(-1 - byte_offset)); | |
| 145 } | |
| 146 | |
| 147 // Patch the detailed stack trace (array of JSObjects with various | |
| 148 // properties). | |
| 149 Handle<Object> detailed_stack_trace_obj = JSReceiver::GetDataProperty( | |
| 150 error, isolate->factory()->detailed_stack_trace_symbol()); | |
| 151 if (detailed_stack_trace_obj->IsJSArray()) { | |
| 152 Handle<FixedArray> stack_elements( | |
| 153 FixedArray::cast(JSArray::cast(*detailed_stack_trace_obj)->elements())); | |
| 154 DCHECK_GE(stack_elements->length(), 1); | |
| 155 Handle<JSObject> top_frame(JSObject::cast(stack_elements->get(0))); | |
| 156 Handle<String> wasm_offset_key = | |
| 157 isolate->factory()->InternalizeOneByteString( | |
| 158 STATIC_CHAR_VECTOR("column")); | |
| 159 LookupIterator it(top_frame, wasm_offset_key, top_frame, | |
| 160 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); | |
| 161 if (it.IsFound()) { | |
| 162 DCHECK(JSReceiver::GetDataProperty(&it)->IsSmi()); | |
| 163 // Make column number 1-based here. | |
| 164 Maybe<bool> data_set = JSReceiver::SetDataProperty( | |
| 165 &it, handle(Smi::FromInt(byte_offset + 1), isolate)); | |
| 166 DCHECK(data_set.IsJust() && data_set.FromJust() == true); | |
| 167 USE(data_set); | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 return isolate->Throw(*error_obj); | |
| 172 } | |
| 173 | |
| 174 RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) { | 120 RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) { |
| 175 SealHandleScope shs(isolate); | 121 SealHandleScope shs(isolate); |
| 176 DCHECK(args.length() == 0); | 122 DCHECK(args.length() == 0); |
| 177 return isolate->UnwindAndFindHandler(); | 123 return isolate->UnwindAndFindHandler(); |
| 178 } | 124 } |
| 179 | 125 |
| 180 | 126 |
| 181 RUNTIME_FUNCTION(Runtime_PromoteScheduledException) { | 127 RUNTIME_FUNCTION(Runtime_PromoteScheduledException) { |
| 182 SealHandleScope shs(isolate); | 128 SealHandleScope shs(isolate); |
| 183 DCHECK(args.length() == 0); | 129 DCHECK(args.length() == 0); |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 461 |
| 516 RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) { | 462 RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) { |
| 517 HandleScope scope(isolate); | 463 HandleScope scope(isolate); |
| 518 DCHECK_EQ(2, args.length()); | 464 DCHECK_EQ(2, args.length()); |
| 519 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0); | 465 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 0); |
| 520 CONVERT_ARG_HANDLE_CHECKED(Object, object, 1); | 466 CONVERT_ARG_HANDLE_CHECKED(Object, object, 1); |
| 521 RETURN_RESULT_OR_FAILURE( | 467 RETURN_RESULT_OR_FAILURE( |
| 522 isolate, Object::OrdinaryHasInstance(isolate, callable, object)); | 468 isolate, Object::OrdinaryHasInstance(isolate, callable, object)); |
| 523 } | 469 } |
| 524 | 470 |
| 525 RUNTIME_FUNCTION(Runtime_IsWasmInstance) { | |
| 526 HandleScope scope(isolate); | |
| 527 DCHECK_EQ(1, args.length()); | |
| 528 CONVERT_ARG_CHECKED(Object, object, 0); | |
| 529 bool is_wasm_instance = | |
| 530 object->IsJSObject() && wasm::IsWasmInstance(JSObject::cast(object)); | |
| 531 return *isolate->factory()->ToBoolean(is_wasm_instance); | |
| 532 } | |
| 533 | |
| 534 RUNTIME_FUNCTION(Runtime_Typeof) { | 471 RUNTIME_FUNCTION(Runtime_Typeof) { |
| 535 HandleScope scope(isolate); | 472 HandleScope scope(isolate); |
| 536 DCHECK_EQ(1, args.length()); | 473 DCHECK_EQ(1, args.length()); |
| 537 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 474 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
| 538 return *Object::TypeOf(isolate, object); | 475 return *Object::TypeOf(isolate, object); |
| 539 } | 476 } |
| 540 | 477 |
| 541 } // namespace internal | 478 } // namespace internal |
| 542 } // namespace v8 | 479 } // namespace v8 |
| OLD | NEW |