| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "src/sampler.h" | 45 #include "src/sampler.h" |
| 46 #include "src/scanner-character-streams.h" | 46 #include "src/scanner-character-streams.h" |
| 47 #include "src/simulator.h" | 47 #include "src/simulator.h" |
| 48 #include "src/snapshot.h" | 48 #include "src/snapshot.h" |
| 49 #include "src/unicode-inl.h" | 49 #include "src/unicode-inl.h" |
| 50 #include "src/v8threads.h" | 50 #include "src/v8threads.h" |
| 51 #include "src/version.h" | 51 #include "src/version.h" |
| 52 #include "src/vm-state-inl.h" | 52 #include "src/vm-state-inl.h" |
| 53 | 53 |
| 54 | 54 |
| 55 namespace v8 { |
| 56 |
| 55 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) | 57 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) |
| 56 | 58 |
| 57 #define ENTER_V8(isolate) \ | |
| 58 i::VMState<v8::OTHER> __state__((isolate)) | |
| 59 | 59 |
| 60 namespace v8 { | 60 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) |
| 61 | |
| 62 #define EXCEPTION_PREAMBLE(isolate) \ | |
| 63 (isolate)->handle_scope_implementer()->IncrementCallDepth(); \ | |
| 64 DCHECK(!(isolate)->external_caught_exception()); \ | |
| 65 bool has_pending_exception = false | |
| 66 | |
| 67 | |
| 68 #define EXCEPTION_BAILOUT_CHECK(isolate, value) \ | |
| 69 do { \ | |
| 70 i::HandleScopeImplementer* handle_scope_implementer = \ | |
| 71 (isolate)->handle_scope_implementer(); \ | |
| 72 handle_scope_implementer->DecrementCallDepth(); \ | |
| 73 if (has_pending_exception) { \ | |
| 74 bool call_depth_is_zero = handle_scope_implementer->CallDepthIsZero(); \ | |
| 75 (isolate)->OptionalRescheduleException(call_depth_is_zero); \ | |
| 76 return value; \ | |
| 77 } \ | |
| 78 } while (false) | |
| 79 | 61 |
| 80 | 62 |
| 81 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ | 63 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ |
| 82 bailout_value, HandleScopeClass, \ | 64 bailout_value, HandleScopeClass, \ |
| 83 do_callback) \ | 65 do_callback) \ |
| 84 if (IsExecutionTerminatingCheck(isolate)) { \ | 66 if (IsExecutionTerminatingCheck(isolate)) { \ |
| 85 return bailout_value; \ | 67 return bailout_value; \ |
| 86 } \ | 68 } \ |
| 87 HandleScopeClass handle_scope(isolate); \ | 69 HandleScopeClass handle_scope(isolate); \ |
| 88 CallDepthScope call_depth_scope(isolate, context, do_callback); \ | 70 CallDepthScope call_depth_scope(isolate, context, do_callback); \ |
| (...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 if (HasCaught()) { | 2075 if (HasCaught()) { |
| 2094 // Check for out of memory exception. | 2076 // Check for out of memory exception. |
| 2095 i::Object* exception = reinterpret_cast<i::Object*>(exception_); | 2077 i::Object* exception = reinterpret_cast<i::Object*>(exception_); |
| 2096 return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_)); | 2078 return v8::Utils::ToLocal(i::Handle<i::Object>(exception, isolate_)); |
| 2097 } else { | 2079 } else { |
| 2098 return v8::Local<Value>(); | 2080 return v8::Local<Value>(); |
| 2099 } | 2081 } |
| 2100 } | 2082 } |
| 2101 | 2083 |
| 2102 | 2084 |
| 2085 MaybeLocal<Value> v8::TryCatch::StackTrace(Local<Context> context) const { |
| 2086 if (!HasCaught()) return v8::Local<Value>(); |
| 2087 i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); |
| 2088 if (!raw_obj->IsJSObject()) return v8::Local<Value>(); |
| 2089 PREPARE_FOR_EXECUTION(context, "v8::TryCatch::StackTrace", Value); |
| 2090 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); |
| 2091 i::Handle<i::String> name = isolate->factory()->stack_string(); |
| 2092 Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name); |
| 2093 has_pending_exception = !maybe.IsJust(); |
| 2094 RETURN_ON_FAILED_EXECUTION(Value); |
| 2095 if (!maybe.FromJust()) return v8::Local<Value>(); |
| 2096 Local<Value> result; |
| 2097 has_pending_exception = |
| 2098 !ToLocal<Value>(i::Object::GetProperty(obj, name), &result); |
| 2099 RETURN_ON_FAILED_EXECUTION(Value); |
| 2100 RETURN_ESCAPED(result); |
| 2101 } |
| 2102 |
| 2103 |
| 2103 v8::Local<Value> v8::TryCatch::StackTrace() const { | 2104 v8::Local<Value> v8::TryCatch::StackTrace() const { |
| 2104 if (HasCaught()) { | 2105 auto context = reinterpret_cast<v8::Isolate*>(isolate_)->GetCurrentContext(); |
| 2105 i::Object* raw_obj = reinterpret_cast<i::Object*>(exception_); | 2106 RETURN_TO_LOCAL_UNCHECKED(StackTrace(context), Value); |
| 2106 if (!raw_obj->IsJSObject()) return v8::Local<Value>(); | |
| 2107 i::HandleScope scope(isolate_); | |
| 2108 i::Handle<i::JSObject> obj(i::JSObject::cast(raw_obj), isolate_); | |
| 2109 i::Handle<i::String> name = isolate_->factory()->stack_string(); | |
| 2110 { | |
| 2111 EXCEPTION_PREAMBLE(isolate_); | |
| 2112 Maybe<bool> maybe = i::JSReceiver::HasProperty(obj, name); | |
| 2113 has_pending_exception = !maybe.IsJust(); | |
| 2114 EXCEPTION_BAILOUT_CHECK(isolate_, v8::Local<Value>()); | |
| 2115 if (!maybe.FromJust()) return v8::Local<Value>(); | |
| 2116 } | |
| 2117 i::Handle<i::Object> value; | |
| 2118 EXCEPTION_PREAMBLE(isolate_); | |
| 2119 has_pending_exception = !i::Object::GetProperty(obj, name).ToHandle(&value); | |
| 2120 EXCEPTION_BAILOUT_CHECK(isolate_, v8::Local<Value>()); | |
| 2121 return v8::Utils::ToLocal(scope.CloseAndEscape(value)); | |
| 2122 } else { | |
| 2123 return v8::Local<Value>(); | |
| 2124 } | |
| 2125 } | 2107 } |
| 2126 | 2108 |
| 2127 | 2109 |
| 2128 v8::Local<v8::Message> v8::TryCatch::Message() const { | 2110 v8::Local<v8::Message> v8::TryCatch::Message() const { |
| 2129 i::Object* message = reinterpret_cast<i::Object*>(message_obj_); | 2111 i::Object* message = reinterpret_cast<i::Object*>(message_obj_); |
| 2130 DCHECK(message->IsJSMessageObject() || message->IsTheHole()); | 2112 DCHECK(message->IsJSMessageObject() || message->IsTheHole()); |
| 2131 if (HasCaught() && !message->IsTheHole()) { | 2113 if (HasCaught() && !message->IsTheHole()) { |
| 2132 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); | 2114 return v8::Utils::MessageToLocal(i::Handle<i::Object>(message, isolate_)); |
| 2133 } else { | 2115 } else { |
| 2134 return v8::Local<v8::Message>(); | 2116 return v8::Local<v8::Message>(); |
| (...skipping 3866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6001 Local<v8::Symbol> v8::SymbolObject::ValueOf() const { | 5983 Local<v8::Symbol> v8::SymbolObject::ValueOf() const { |
| 6002 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 5984 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 6003 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); | 5985 i::Handle<i::JSValue> jsvalue = i::Handle<i::JSValue>::cast(obj); |
| 6004 i::Isolate* isolate = jsvalue->GetIsolate(); | 5986 i::Isolate* isolate = jsvalue->GetIsolate(); |
| 6005 LOG_API(isolate, "SymbolObject::SymbolValue"); | 5987 LOG_API(isolate, "SymbolObject::SymbolValue"); |
| 6006 return Utils::ToLocal( | 5988 return Utils::ToLocal( |
| 6007 i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()))); | 5989 i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()))); |
| 6008 } | 5990 } |
| 6009 | 5991 |
| 6010 | 5992 |
| 5993 MaybeLocal<v8::Value> v8::Date::New(Local<Context> context, double time) { |
| 5994 if (std::isnan(time)) { |
| 5995 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. |
| 5996 time = std::numeric_limits<double>::quiet_NaN(); |
| 5997 } |
| 5998 PREPARE_FOR_EXECUTION(context, "Date::New", Value); |
| 5999 Local<Value> result; |
| 6000 has_pending_exception = |
| 6001 !ToLocal<Value>(i::Execution::NewDate(isolate, time), &result); |
| 6002 RETURN_ON_FAILED_EXECUTION(Value); |
| 6003 RETURN_ESCAPED(result); |
| 6004 } |
| 6005 |
| 6006 |
| 6011 Local<v8::Value> v8::Date::New(Isolate* isolate, double time) { | 6007 Local<v8::Value> v8::Date::New(Isolate* isolate, double time) { |
| 6012 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 6008 auto context = isolate->GetCurrentContext(); |
| 6013 LOG_API(i_isolate, "Date::New"); | 6009 RETURN_TO_LOCAL_UNCHECKED(New(context, time), Value); |
| 6014 if (std::isnan(time)) { | |
| 6015 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. | |
| 6016 time = std::numeric_limits<double>::quiet_NaN(); | |
| 6017 } | |
| 6018 ENTER_V8(i_isolate); | |
| 6019 EXCEPTION_PREAMBLE(i_isolate); | |
| 6020 i::Handle<i::Object> obj; | |
| 6021 has_pending_exception = !i::Execution::NewDate( | |
| 6022 i_isolate, time).ToHandle(&obj); | |
| 6023 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::Value>()); | |
| 6024 return Utils::ToLocal(obj); | |
| 6025 } | 6010 } |
| 6026 | 6011 |
| 6027 | 6012 |
| 6028 double v8::Date::ValueOf() const { | 6013 double v8::Date::ValueOf() const { |
| 6029 i::Handle<i::Object> obj = Utils::OpenHandle(this); | 6014 i::Handle<i::Object> obj = Utils::OpenHandle(this); |
| 6030 i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); | 6015 i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); |
| 6031 i::Isolate* isolate = jsdate->GetIsolate(); | 6016 i::Isolate* isolate = jsdate->GetIsolate(); |
| 6032 LOG_API(isolate, "Date::NumberValue"); | 6017 LOG_API(isolate, "Date::NumberValue"); |
| 6033 return jsdate->value()->Number(); | 6018 return jsdate->value()->Number(); |
| 6034 } | 6019 } |
| (...skipping 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8025 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8010 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
| 8026 Address callback_address = | 8011 Address callback_address = |
| 8027 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8012 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8028 VMState<EXTERNAL> state(isolate); | 8013 VMState<EXTERNAL> state(isolate); |
| 8029 ExternalCallbackScope call_scope(isolate, callback_address); | 8014 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8030 callback(info); | 8015 callback(info); |
| 8031 } | 8016 } |
| 8032 | 8017 |
| 8033 | 8018 |
| 8034 } } // namespace v8::internal | 8019 } } // namespace v8::internal |
| OLD | NEW |