summaryrefslogtreecommitdiff
path: root/libdeno/api.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libdeno/api.cc')
-rw-r--r--libdeno/api.cc37
1 files changed, 14 insertions, 23 deletions
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<Deno*>(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<v8::Value> 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);
}
}
}