Chromium Code Reviews| 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 2550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2561 options = static_cast<StackTraceOptions>( | 2561 options = static_cast<StackTraceOptions>( |
| 2562 static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins); | 2562 static_cast<int>(options) | kExposeFramesAcrossSecurityOrigins); |
| 2563 i::Handle<i::JSArray> stackTrace = | 2563 i::Handle<i::JSArray> stackTrace = |
| 2564 i_isolate->CaptureCurrentStackTrace(frame_limit, options); | 2564 i_isolate->CaptureCurrentStackTrace(frame_limit, options); |
| 2565 return Utils::StackTraceToLocal(stackTrace); | 2565 return Utils::StackTraceToLocal(stackTrace); |
| 2566 } | 2566 } |
| 2567 | 2567 |
| 2568 | 2568 |
| 2569 // --- S t a c k F r a m e --- | 2569 // --- S t a c k F r a m e --- |
| 2570 | 2570 |
| 2571 #define STACKFRAME_PROPERTY_HELPER(obj, propertyName, MAKE_SCOPE) \ | |
|
titzer
2016/04/22 12:16:25
As tempting as this is, let's not macro-ify this c
Clemens Hammacher
2016/04/26 14:00:10
Hm, OK.
| |
| 2572 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); \ | |
| 2573 ENTER_V8(isolate); \ | |
| 2574 MAKE_SCOPE(scope, isolate); \ | |
| 2575 i::Handle<i::JSObject> self = Utils::OpenHandle(f); \ | |
| 2576 i::Handle<i::Object> obj = \ | |
| 2577 i::JSReceiver::GetProperty(isolate, self, propertyName) \ | |
| 2578 .ToHandleChecked(); | |
| 2579 #define MAKE_STD_SCOPE(name, isolate) i::HandleScope name(isolate) | |
| 2580 #define STACKFRAME_PROPERTY(obj, propertyName) \ | |
| 2581 STACKFRAME_PROPERTY_HELPER(obj, propertyName, MAKE_STD_SCOPE) | |
| 2582 #define MAKE_ESCAPABLE_SCOPE(name, isolate) \ | |
| 2583 EscapableHandleScope name(reinterpret_cast<Isolate*>(isolate)) | |
| 2584 #define STACKFRAME_ESCAPABLE_PROPERTY(obj, propertyName) \ | |
| 2585 STACKFRAME_PROPERTY_HELPER(obj, propertyName, MAKE_ESCAPABLE_SCOPE) | |
| 2586 | |
| 2571 static int getIntProperty(const StackFrame* f, const char* propertyName, | 2587 static int getIntProperty(const StackFrame* f, const char* propertyName, |
| 2572 int defaultValue) { | 2588 int defaultValue) { |
| 2573 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | 2589 STACKFRAME_PROPERTY(obj, propertyName) |
| 2574 ENTER_V8(isolate); | |
| 2575 i::HandleScope scope(isolate); | |
| 2576 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | |
| 2577 i::Handle<i::Object> obj = | |
| 2578 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
| 2579 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; | 2590 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; |
| 2580 } | 2591 } |
| 2581 | 2592 |
| 2593 static uint32_t getUintProperty(const StackFrame* f, const char* propertyName, | |
| 2594 uint32_t defaultValue) { | |
| 2595 STACKFRAME_PROPERTY(obj, propertyName) | |
| 2596 uint32_t val = defaultValue; | |
| 2597 obj->ToUint32(&val); | |
| 2598 return val; | |
| 2599 } | |
| 2600 | |
| 2601 static Local<String> getStringProperty(const StackFrame* f, | |
| 2602 const char* propertyName) { | |
| 2603 STACKFRAME_ESCAPABLE_PROPERTY(obj, propertyName) | |
| 2604 return obj->IsString() | |
| 2605 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) | |
| 2606 : Local<String>(); | |
| 2607 } | |
| 2608 | |
| 2609 static Local<Object> getObjectProperty(const StackFrame* f, | |
| 2610 const char* propertyName) { | |
| 2611 STACKFRAME_ESCAPABLE_PROPERTY(obj, propertyName); | |
| 2612 return obj->IsObject() | |
| 2613 ? scope.Escape(Local<Object>::Cast(Utils::ToLocal(obj))) | |
| 2614 : Local<Object>(); | |
| 2615 } | |
| 2616 | |
| 2617 static bool getBoolProperty(const StackFrame* f, const char* propertyName) { | |
| 2618 STACKFRAME_PROPERTY(obj, propertyName); | |
| 2619 return obj->IsTrue(); | |
| 2620 } | |
| 2582 | 2621 |
| 2583 int StackFrame::GetLineNumber() const { | 2622 int StackFrame::GetLineNumber() const { |
| 2584 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); | 2623 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); |
| 2585 } | 2624 } |
| 2586 | 2625 |
| 2587 | 2626 |
| 2588 int StackFrame::GetColumn() const { | 2627 int StackFrame::GetColumn() const { |
| 2589 return getIntProperty(this, "column", Message::kNoColumnInfo); | 2628 return getIntProperty(this, "column", Message::kNoColumnInfo); |
| 2590 } | 2629 } |
| 2591 | 2630 |
| 2592 | 2631 |
| 2593 int StackFrame::GetScriptId() const { | 2632 int StackFrame::GetScriptId() const { |
| 2594 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); | 2633 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); |
| 2595 } | 2634 } |
| 2596 | 2635 |
| 2597 | |
| 2598 static Local<String> getStringProperty(const StackFrame* f, | |
| 2599 const char* propertyName) { | |
| 2600 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | |
| 2601 ENTER_V8(isolate); | |
| 2602 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | |
| 2603 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | |
| 2604 i::Handle<i::Object> obj = | |
| 2605 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
| 2606 return obj->IsString() | |
| 2607 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) | |
| 2608 : Local<String>(); | |
| 2609 } | |
| 2610 | |
| 2611 | |
| 2612 Local<String> StackFrame::GetScriptName() const { | 2636 Local<String> StackFrame::GetScriptName() const { |
| 2613 return getStringProperty(this, "scriptName"); | 2637 return getStringProperty(this, "scriptName"); |
| 2614 } | 2638 } |
| 2615 | 2639 |
| 2616 | 2640 |
| 2617 Local<String> StackFrame::GetScriptNameOrSourceURL() const { | 2641 Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
| 2618 return getStringProperty(this, "scriptNameOrSourceURL"); | 2642 return getStringProperty(this, "scriptNameOrSourceURL"); |
| 2619 } | 2643 } |
| 2620 | 2644 |
| 2621 | 2645 |
| 2622 Local<String> StackFrame::GetFunctionName() const { | 2646 Local<String> StackFrame::GetFunctionName() const { |
| 2623 return getStringProperty(this, "functionName"); | 2647 return getStringProperty(this, "functionName"); |
| 2624 } | 2648 } |
| 2625 | 2649 |
| 2626 | |
| 2627 static bool getBoolProperty(const StackFrame* f, const char* propertyName) { | |
| 2628 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | |
| 2629 ENTER_V8(isolate); | |
| 2630 i::HandleScope scope(isolate); | |
| 2631 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | |
| 2632 i::Handle<i::Object> obj = | |
| 2633 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
| 2634 return obj->IsTrue(); | |
| 2635 } | |
| 2636 | |
| 2637 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } | 2650 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } |
| 2638 | 2651 |
| 2639 | 2652 |
| 2640 bool StackFrame::IsConstructor() const { | 2653 bool StackFrame::IsConstructor() const { |
| 2641 return getBoolProperty(this, "isConstructor"); | 2654 return getBoolProperty(this, "isConstructor"); |
| 2642 } | 2655 } |
| 2643 | 2656 |
| 2657 bool StackFrame::IsWasm() const { return getBoolProperty(this, "isWasm"); } | |
| 2658 | |
| 2659 Local<Object> StackFrame::GetWasmObject() const { | |
| 2660 return getObjectProperty(this, "wasmObject"); | |
| 2661 } | |
| 2662 | |
| 2663 uint32_t StackFrame::GetWasmByteOffset() const { | |
| 2664 return getUintProperty(this, "wasmByteOffset", | |
| 2665 Message::kNoWasmByteOffsetInfo); | |
| 2666 } | |
| 2644 | 2667 |
| 2645 // --- N a t i v e W e a k M a p --- | 2668 // --- N a t i v e W e a k M a p --- |
| 2646 | 2669 |
| 2647 Local<NativeWeakMap> NativeWeakMap::New(Isolate* v8_isolate) { | 2670 Local<NativeWeakMap> NativeWeakMap::New(Isolate* v8_isolate) { |
| 2648 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 2671 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 2649 ENTER_V8(isolate); | 2672 ENTER_V8(isolate); |
| 2650 i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); | 2673 i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); |
| 2651 i::JSWeakCollection::Initialize(weakmap, isolate); | 2674 i::JSWeakCollection::Initialize(weakmap, isolate); |
| 2652 return Utils::NativeWeakMapToLocal(weakmap); | 2675 return Utils::NativeWeakMapToLocal(weakmap); |
| 2653 } | 2676 } |
| (...skipping 6180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8834 Address callback_address = | 8857 Address callback_address = |
| 8835 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8858 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8836 VMState<EXTERNAL> state(isolate); | 8859 VMState<EXTERNAL> state(isolate); |
| 8837 ExternalCallbackScope call_scope(isolate, callback_address); | 8860 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8838 callback(info); | 8861 callback(info); |
| 8839 } | 8862 } |
| 8840 | 8863 |
| 8841 | 8864 |
| 8842 } // namespace internal | 8865 } // namespace internal |
| 8843 } // namespace v8 | 8866 } // namespace v8 |
| OLD | NEW |