OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api.h" | 5 #include "src/api.h" |
6 | 6 |
7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
(...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2440 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2440 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
2441 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); | 2441 auto message = i::Handle<i::JSMessageObject>::cast(Utils::OpenHandle(this)); |
2442 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); | 2442 i::Handle<i::Object> stackFramesObj(message->stack_frames(), isolate); |
2443 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); | 2443 if (!stackFramesObj->IsJSArray()) return v8::Local<v8::StackTrace>(); |
2444 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); | 2444 auto stackTrace = i::Handle<i::JSArray>::cast(stackFramesObj); |
2445 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); | 2445 return scope.Escape(Utils::StackTraceToLocal(stackTrace)); |
2446 } | 2446 } |
2447 | 2447 |
2448 | 2448 |
2449 Maybe<int> Message::GetLineNumber(Local<Context> context) const { | 2449 Maybe<int> Message::GetLineNumber(Local<Context> context) const { |
2450 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetLineNumber, int); | 2450 auto self = Utils::OpenHandle(this); |
2451 i::Handle<i::JSFunction> fun = isolate->message_get_line_number(); | 2451 i::Isolate* isolate = self->GetIsolate(); |
2452 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | 2452 ENTER_V8(isolate); |
2453 i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; | 2453 EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate)); |
2454 i::Handle<i::Object> result; | 2454 auto msg = i::Handle<i::JSMessageObject>::cast(self); |
2455 has_pending_exception = | 2455 return Just(msg->GetLineNumber()); |
2456 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | |
2457 .ToHandle(&result); | |
2458 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); | |
2459 return Just(static_cast<int>(result->Number())); | |
2460 } | 2456 } |
2461 | 2457 |
2462 | 2458 |
2463 int Message::GetLineNumber() const { | 2459 int Message::GetLineNumber() const { |
2464 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 2460 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
2465 return GetLineNumber(context).FromMaybe(0); | 2461 return GetLineNumber(context).FromMaybe(0); |
2466 } | 2462 } |
2467 | 2463 |
2468 | 2464 |
2469 int Message::GetStartPosition() const { | 2465 int Message::GetStartPosition() const { |
2470 auto self = Utils::OpenHandle(this); | 2466 auto self = Utils::OpenHandle(this); |
2471 return self->start_position(); | 2467 return self->start_position(); |
2472 } | 2468 } |
2473 | 2469 |
2474 | 2470 |
2475 int Message::GetEndPosition() const { | 2471 int Message::GetEndPosition() const { |
2476 auto self = Utils::OpenHandle(this); | 2472 auto self = Utils::OpenHandle(this); |
2477 return self->end_position(); | 2473 return self->end_position(); |
2478 } | 2474 } |
2479 | 2475 |
2480 | 2476 |
2481 Maybe<int> Message::GetStartColumn(Local<Context> context) const { | 2477 Maybe<int> Message::GetStartColumn(Local<Context> context) const { |
2482 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetStartColumn, int); | 2478 auto self = Utils::OpenHandle(this); |
2483 i::Handle<i::JSFunction> fun = isolate->message_get_column_number(); | 2479 i::Isolate* isolate = self->GetIsolate(); |
2484 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | 2480 ENTER_V8(isolate); |
2485 i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; | 2481 EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate)); |
2486 i::Handle<i::Object> result; | 2482 auto msg = i::Handle<i::JSMessageObject>::cast(self); |
2487 has_pending_exception = | 2483 return Just(msg->GetColumnNumber()); |
2488 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | |
2489 .ToHandle(&result); | |
2490 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); | |
2491 return Just(static_cast<int>(result->Number())); | |
2492 } | 2484 } |
2493 | 2485 |
2494 | 2486 |
2495 int Message::GetStartColumn() const { | 2487 int Message::GetStartColumn() const { |
2496 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 2488 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
2497 const int default_value = kNoColumnInfo; | 2489 const int default_value = kNoColumnInfo; |
2498 return GetStartColumn(context).FromMaybe(default_value); | 2490 return GetStartColumn(context).FromMaybe(default_value); |
2499 } | 2491 } |
2500 | 2492 |
2501 | 2493 |
2502 Maybe<int> Message::GetEndColumn(Local<Context> context) const { | 2494 Maybe<int> Message::GetEndColumn(Local<Context> context) const { |
2503 auto self = Utils::OpenHandle(this); | 2495 auto self = Utils::OpenHandle(this); |
2504 PREPARE_FOR_EXECUTION_PRIMITIVE(context, Message, GetEndColumn, int); | 2496 i::Isolate* isolate = self->GetIsolate(); |
2505 i::Handle<i::JSFunction> fun = isolate->message_get_column_number(); | 2497 ENTER_V8(isolate); |
2506 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | 2498 EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate)); |
2507 i::Handle<i::Object> args[] = {self}; | 2499 auto msg = i::Handle<i::JSMessageObject>::cast(self); |
2508 i::Handle<i::Object> result; | 2500 const int column_number = msg->GetColumnNumber(); |
2509 has_pending_exception = | 2501 if (column_number == -1) return Just(-1); |
2510 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | 2502 const int start = self->start_position(); |
2511 .ToHandle(&result); | 2503 const int end = self->end_position(); |
2512 RETURN_ON_FAILED_EXECUTION_PRIMITIVE(int); | 2504 return Just(column_number + (end - start)); |
2513 int start = self->start_position(); | |
2514 int end = self->end_position(); | |
2515 return Just(static_cast<int>(result->Number()) + (end - start)); | |
2516 } | 2505 } |
2517 | 2506 |
2518 | 2507 |
2519 int Message::GetEndColumn() const { | 2508 int Message::GetEndColumn() const { |
2520 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 2509 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
2521 const int default_value = kNoColumnInfo; | 2510 const int default_value = kNoColumnInfo; |
2522 return GetEndColumn(context).FromMaybe(default_value); | 2511 return GetEndColumn(context).FromMaybe(default_value); |
2523 } | 2512 } |
2524 | 2513 |
2525 | 2514 |
(...skipping 12 matching lines...) Expand all Loading... |
2538 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 2527 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
2539 ENTER_V8(isolate); | 2528 ENTER_V8(isolate); |
2540 auto self = Utils::OpenHandle(this); | 2529 auto self = Utils::OpenHandle(this); |
2541 auto script = i::Handle<i::JSValue>::cast( | 2530 auto script = i::Handle<i::JSValue>::cast( |
2542 i::Handle<i::Object>(self->script(), isolate)); | 2531 i::Handle<i::Object>(self->script(), isolate)); |
2543 return i::Script::cast(script->value())->origin_options().IsOpaque(); | 2532 return i::Script::cast(script->value())->origin_options().IsOpaque(); |
2544 } | 2533 } |
2545 | 2534 |
2546 | 2535 |
2547 MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const { | 2536 MaybeLocal<String> Message::GetSourceLine(Local<Context> context) const { |
2548 PREPARE_FOR_EXECUTION(context, Message, GetSourceLine, String); | 2537 auto self = Utils::OpenHandle(this); |
2549 i::Handle<i::JSFunction> fun = isolate->message_get_source_line(); | 2538 i::Isolate* isolate = self->GetIsolate(); |
2550 i::Handle<i::Object> undefined = isolate->factory()->undefined_value(); | 2539 ENTER_V8(isolate); |
2551 i::Handle<i::Object> args[] = {Utils::OpenHandle(this)}; | 2540 EscapableHandleScope handle_scope(reinterpret_cast<Isolate*>(isolate)); |
2552 i::Handle<i::Object> result; | 2541 auto msg = i::Handle<i::JSMessageObject>::cast(self); |
2553 has_pending_exception = | 2542 RETURN_ESCAPED(Utils::ToLocal(msg->GetSourceLine())); |
2554 !i::Execution::Call(isolate, fun, undefined, arraysize(args), args) | |
2555 .ToHandle(&result); | |
2556 RETURN_ON_FAILED_EXECUTION(String); | |
2557 Local<String> str; | |
2558 if (result->IsString()) { | |
2559 str = Utils::ToLocal(i::Handle<i::String>::cast(result)); | |
2560 } | |
2561 RETURN_ESCAPED(str); | |
2562 } | 2543 } |
2563 | 2544 |
2564 | 2545 |
2565 Local<String> Message::GetSourceLine() const { | 2546 Local<String> Message::GetSourceLine() const { |
2566 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); | 2547 auto context = ContextFromHeapObject(Utils::OpenHandle(this)); |
2567 RETURN_TO_LOCAL_UNCHECKED(GetSourceLine(context), String) | 2548 RETURN_TO_LOCAL_UNCHECKED(GetSourceLine(context), String) |
2568 } | 2549 } |
2569 | 2550 |
2570 | 2551 |
2571 void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) { | 2552 void Message::PrintCurrentStackTrace(Isolate* isolate, FILE* out) { |
(...skipping 6462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9034 Address callback_address = | 9015 Address callback_address = |
9035 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 9016 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
9036 VMState<EXTERNAL> state(isolate); | 9017 VMState<EXTERNAL> state(isolate); |
9037 ExternalCallbackScope call_scope(isolate, callback_address); | 9018 ExternalCallbackScope call_scope(isolate, callback_address); |
9038 callback(info); | 9019 callback(info); |
9039 } | 9020 } |
9040 | 9021 |
9041 | 9022 |
9042 } // namespace internal | 9023 } // namespace internal |
9043 } // namespace v8 | 9024 } // namespace v8 |
OLD | NEW |