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 2561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2572 int defaultValue) { | 2572 int defaultValue) { |
2573 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | 2573 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); |
2574 ENTER_V8(isolate); | 2574 ENTER_V8(isolate); |
2575 i::HandleScope scope(isolate); | 2575 i::HandleScope scope(isolate); |
2576 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | 2576 i::Handle<i::JSObject> self = Utils::OpenHandle(f); |
2577 i::Handle<i::Object> obj = | 2577 i::Handle<i::Object> obj = |
2578 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | 2578 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); |
2579 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; | 2579 return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue; |
2580 } | 2580 } |
2581 | 2581 |
2582 | 2582 static uint32_t getUintProperty(const StackFrame* f, const char* propertyName, |
2583 int StackFrame::GetLineNumber() const { | 2583 uint32_t defaultValue) { |
2584 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); | 2584 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); |
2585 ENTER_V8(isolate); | |
2586 i::HandleScope scope(isolate); | |
2587 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | |
2588 i::Handle<i::Object> obj = | |
2589 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
2590 uint32_t val = defaultValue; | |
2591 obj->ToUint32(&val); | |
2592 return val; | |
2585 } | 2593 } |
2586 | 2594 |
2587 | |
2588 int StackFrame::GetColumn() const { | |
2589 return getIntProperty(this, "column", Message::kNoColumnInfo); | |
2590 } | |
2591 | |
2592 | |
2593 int StackFrame::GetScriptId() const { | |
2594 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); | |
2595 } | |
2596 | |
2597 | |
2598 static Local<String> getStringProperty(const StackFrame* f, | 2595 static Local<String> getStringProperty(const StackFrame* f, |
2599 const char* propertyName) { | 2596 const char* propertyName) { |
2600 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | 2597 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); |
2601 ENTER_V8(isolate); | 2598 ENTER_V8(isolate); |
2602 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | 2599 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); |
2603 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | 2600 i::Handle<i::JSObject> self = Utils::OpenHandle(f); |
2604 i::Handle<i::Object> obj = | 2601 i::Handle<i::Object> obj = |
2605 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | 2602 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); |
2606 return obj->IsString() | 2603 return obj->IsString() |
2607 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) | 2604 ? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj))) |
2608 : Local<String>(); | 2605 : Local<String>(); |
2609 } | 2606 } |
2610 | 2607 |
2608 static Local<Object> getObjectProperty(const StackFrame* f, | |
2609 const char* propertyName) { | |
2610 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | |
2611 ENTER_V8(isolate); | |
2612 EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); | |
2613 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | |
2614 i::Handle<i::Object> obj = | |
2615 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
2616 return obj->IsObject() | |
2617 ? scope.Escape(Local<Object>::Cast(Utils::ToLocal(obj))) | |
2618 : Local<Object>(); | |
2619 } | |
2620 | |
2621 static bool getBoolProperty(const StackFrame* f, const char* propertyName) { | |
2622 i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate(); | |
2623 ENTER_V8(isolate); | |
2624 i::HandleScope scope(isolate); | |
2625 i::Handle<i::JSObject> self = Utils::OpenHandle(f); | |
2626 i::Handle<i::Object> obj = | |
2627 i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked(); | |
2628 return obj->IsTrue(); | |
2629 } | |
2630 | |
2631 int StackFrame::GetLineNumber() const { | |
2632 return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo); | |
2633 } | |
2634 | |
2635 int StackFrame::GetColumn() const { | |
2636 return getIntProperty(this, "column", Message::kNoColumnInfo); | |
2637 } | |
2638 | |
2639 int StackFrame::GetScriptId() const { | |
2640 return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo); | |
2641 } | |
2611 | 2642 |
2612 Local<String> StackFrame::GetScriptName() const { | 2643 Local<String> StackFrame::GetScriptName() const { |
2613 return getStringProperty(this, "scriptName"); | 2644 return getStringProperty(this, "scriptName"); |
2614 } | 2645 } |
2615 | 2646 |
2616 | 2647 |
2617 Local<String> StackFrame::GetScriptNameOrSourceURL() const { | 2648 Local<String> StackFrame::GetScriptNameOrSourceURL() const { |
2618 return getStringProperty(this, "scriptNameOrSourceURL"); | 2649 return getStringProperty(this, "scriptNameOrSourceURL"); |
2619 } | 2650 } |
2620 | 2651 |
2621 | 2652 |
2622 Local<String> StackFrame::GetFunctionName() const { | 2653 Local<String> StackFrame::GetFunctionName() const { |
2623 return getStringProperty(this, "functionName"); | 2654 return getStringProperty(this, "functionName"); |
2624 } | 2655 } |
2625 | 2656 |
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"); } | 2657 bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); } |
2638 | 2658 |
2639 | 2659 |
2640 bool StackFrame::IsConstructor() const { | 2660 bool StackFrame::IsConstructor() const { |
2641 return getBoolProperty(this, "isConstructor"); | 2661 return getBoolProperty(this, "isConstructor"); |
2642 } | 2662 } |
2643 | 2663 |
2664 bool StackFrame::IsWasm() const { return getBoolProperty(this, "isWasm"); } | |
2665 | |
2666 Local<Object> StackFrame::GetWasmObject() const { | |
2667 return getObjectProperty(this, "wasmObject"); | |
Yang
2016/04/28 13:08:43
This should also not be called if IsWasm() returns
| |
2668 } | |
2669 | |
2670 uint32_t StackFrame::GetWasmByteOffset() const { | |
2671 return getUintProperty(this, "wasmByteOffset", | |
2672 Message::kNoWasmByteOffsetInfo); | |
2673 } | |
2644 | 2674 |
2645 // --- N a t i v e W e a k M a p --- | 2675 // --- N a t i v e W e a k M a p --- |
2646 | 2676 |
2647 Local<NativeWeakMap> NativeWeakMap::New(Isolate* v8_isolate) { | 2677 Local<NativeWeakMap> NativeWeakMap::New(Isolate* v8_isolate) { |
2648 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 2678 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
2649 ENTER_V8(isolate); | 2679 ENTER_V8(isolate); |
2650 i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); | 2680 i::Handle<i::JSWeakMap> weakmap = isolate->factory()->NewJSWeakMap(); |
2651 i::JSWeakCollection::Initialize(weakmap, isolate); | 2681 i::JSWeakCollection::Initialize(weakmap, isolate); |
2652 return Utils::NativeWeakMapToLocal(weakmap); | 2682 return Utils::NativeWeakMapToLocal(weakmap); |
2653 } | 2683 } |
(...skipping 6184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8838 Address callback_address = | 8868 Address callback_address = |
8839 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8869 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8840 VMState<EXTERNAL> state(isolate); | 8870 VMState<EXTERNAL> state(isolate); |
8841 ExternalCallbackScope call_scope(isolate, callback_address); | 8871 ExternalCallbackScope call_scope(isolate, callback_address); |
8842 callback(info); | 8872 callback(info); |
8843 } | 8873 } |
8844 | 8874 |
8845 | 8875 |
8846 } // namespace internal | 8876 } // namespace internal |
8847 } // namespace v8 | 8877 } // namespace v8 |
OLD | NEW |