@@ -109,10 +109,6 @@ namespace v8impl {
109109
110110// === Conversion between V8 Isolate and napi_env ==========================
111111
112- v8::Isolate* V8IsolateFromJsEnv (napi_env e) {
113- return reinterpret_cast <v8::Isolate*>(e);
114- }
115-
116112class HandleScopeWrapper {
117113 public:
118114 explicit HandleScopeWrapper (
@@ -148,6 +144,15 @@ v8::Local<v8::Value> V8LocalValueFromJsValue(napi_value v) {
148144 memcpy (&local, &v, sizeof (v));
149145 return local;
150146}
147+
148+ inline void TriggerFatalException (
149+ napi_env env, v8::Local<v8::Value> local_err) {
150+ // The API requires V8 types, so use the shim until there are engine-neutral
151+ // core APIs.
152+ v8::Local<v8::Message> local_msg =
153+ v8::Exception::CreateMessage (env->isolate , local_err);
154+ node::FatalException (env->isolate , local_err, local_msg);
155+ }
151156} // end of namespace v8impl
152157
153158namespace jsrtimpl {
@@ -619,6 +624,16 @@ napi_status napi_set_last_error(JsErrorCode jsError, void* engine_reserved) {
619624 return status;
620625}
621626
627+ napi_status napi_fatal_exception (napi_env env, napi_value err) {
628+ CHECK_ARG (err);
629+
630+ v8::Local<v8::Value> local_err = v8impl::V8LocalValueFromJsValue (err);
631+ v8impl::TriggerFatalException (env, local_err);
632+
633+ napi_clear_last_error ();
634+ return napi_ok;
635+ }
636+
622637NAPI_NO_RETURN void napi_fatal_error (const char * location,
623638 size_t location_len,
624639 const char * message,
@@ -2139,7 +2154,7 @@ napi_status napi_make_callback(napi_env env,
21392154 size_t argc,
21402155 const napi_value* argv,
21412156 napi_value* result) {
2142- v8::Isolate* isolate = v8impl::V8IsolateFromJsEnv ( env) ;
2157+ v8::Isolate* isolate = env-> isolate ;
21432158 v8::Local<v8::Object> v8recv =
21442159 v8impl::V8LocalValueFromJsValue (recv).As <v8::Object>();
21452160 v8::Local<v8::Function> v8func =
@@ -2197,7 +2212,7 @@ napi_status napi_create_buffer(napi_env env,
21972212 // TODO(tawoll): Replace v8impl with jsrt-based version.
21982213
21992214 v8::MaybeLocal<v8::Object> maybe =
2200- node::Buffer::New (v8impl::V8IsolateFromJsEnv ( env) , length);
2215+ node::Buffer::New (env-> isolate , length);
22012216 if (maybe.IsEmpty ()) {
22022217 return napi_generic_failure;
22032218 }
@@ -2223,7 +2238,7 @@ napi_status napi_create_external_buffer(napi_env env,
22232238 jsrtimpl::ExternalData* externalData = new jsrtimpl::ExternalData (
22242239 env, data, finalize_cb, finalize_hint);
22252240 v8::MaybeLocal<v8::Object> maybe = node::Buffer::New (
2226- v8impl::V8IsolateFromJsEnv ( env) ,
2241+ env-> isolate ,
22272242 static_cast <char *>(data),
22282243 length,
22292244 jsrtimpl::ExternalData::FinalizeBuffer,
@@ -2247,7 +2262,7 @@ napi_status napi_create_buffer_copy(napi_env env,
22472262 // chakra shim here.
22482263
22492264 v8::MaybeLocal<v8::Object> maybe = node::Buffer::Copy (
2250- v8impl::V8IsolateFromJsEnv ( env) , static_cast <const char *>(data), length);
2265+ env-> isolate , static_cast <const char *>(data), length);
22512266 if (maybe.IsEmpty ()) {
22522267 return napi_generic_failure;
22532268 }
0 commit comments