From c113df1bb8a0c7d0c560ad32c0291c918c7da7b4 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 6 Dec 2018 23:05:36 -0500 Subject: Process source maps in Rust instead of JS (#1280) - Improves speed and binary size significantly. - Makes deno_last_exception() output a JSON structure. - Isolate::execute and Isolate::event_loop now return structured, mapped JSError objects on errors. - Removes libdeno functions: libdeno.setGlobalErrorHandler() libdeno.setPromiseRejectHandler() libdeno.setPromiseErrorExaminer() In collaboration with Ryan Dahl. --- libdeno/api.cc | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) (limited to 'libdeno/api.cc') diff --git a/libdeno/api.cc b/libdeno/api.cc index 6f4ac826f..388ab6146 100644 --- a/libdeno/api.cc +++ b/libdeno/api.cc @@ -38,7 +38,7 @@ Deno* deno_new(deno_buf snapshot, deno_config config) { if (!snapshot.data_ptr) { // If no snapshot is provided, we initialize the context with empty // main source code and source maps. - deno::InitializeContext(isolate, context, "", "", ""); + deno::InitializeContext(isolate, context, "", ""); } d->context_.Reset(isolate, context); } @@ -47,7 +47,7 @@ Deno* deno_new(deno_buf snapshot, deno_config config) { } Deno* deno_new_snapshotter(deno_config config, const char* js_filename, - const char* js_source, const char* source_map) { + const char* js_source) { auto* creator = new v8::SnapshotCreator(deno::external_references); auto* isolate = creator->GetIsolate(); auto* d = new deno::DenoIsolate(deno::empty_buf, config); @@ -61,8 +61,7 @@ Deno* deno_new_snapshotter(deno_config config, const char* js_filename, creator->SetDefaultContext(context, v8::SerializeInternalFieldsCallback( deno::SerializeInternalFields, nullptr)); - deno::InitializeContext(isolate, context, js_filename, js_source, - source_map); + deno::InitializeContext(isolate, context, js_filename, js_source); } return reinterpret_cast(d); } @@ -96,7 +95,11 @@ void deno_set_v8_flags(int* argc, char** argv) { const char* deno_last_exception(Deno* d_) { auto* d = unwrap(d_); - return d->last_exception_.c_str(); + if (d->last_exception_.length() > 0) { + return d->last_exception_.c_str(); + } else { + return nullptr; + } } int deno_execute(Deno* d_, void* user_data, const char* js_filename, @@ -154,31 +157,19 @@ int deno_respond(Deno* d_, void* user_data, int32_t req_id, deno_buf buf) { void deno_check_promise_errors(Deno* d_) { auto* d = unwrap(d_); - if (d->pending_promise_events_ > 0) { + if (d->pending_promise_map_.size() > 0) { auto* isolate = d->isolate_; v8::Locker locker(isolate); v8::Isolate::Scope isolate_scope(isolate); v8::HandleScope handle_scope(isolate); - auto context = d->context_.Get(d->isolate_); v8::Context::Scope context_scope(context); - v8::TryCatch try_catch(d->isolate_); - auto promise_error_examiner_ = d->promise_error_examiner_.Get(d->isolate_); - if (promise_error_examiner_.IsEmpty()) { - d->last_exception_ = - "libdeno.setPromiseErrorExaminer has not been called."; - return; - } - v8::Local args[0]; - auto result = promise_error_examiner_->Call(context->Global(), 0, args); - if (try_catch.HasCaught()) { - deno::HandleException(context, try_catch.Exception()); - } - d->pending_promise_events_ = 0; // reset - if (!result->BooleanValue(context).FromJust()) { - // Has uncaught promise reject error, exiting... - exit(1); + auto it = d->pending_promise_map_.begin(); + while (it != d->pending_promise_map_.end()) { + auto error = it->second.Get(isolate); + deno::HandleException(context, error); + it = d->pending_promise_map_.erase(it); } } } -- cgit v1.2.3