From fdd4252d49ceb022761b92d953d24672ab67ab91 Mon Sep 17 00:00:00 2001 From: "Kevin (Kun) \"Kassimo\" Qian" Date: Sat, 31 Aug 2019 12:16:30 -0700 Subject: Add window.queueMicrotask (#2844) --- core/libdeno/binding.cc | 19 +++++++++++++++++++ core/libdeno/internal.h | 2 ++ 2 files changed, 21 insertions(+) (limited to 'core') diff --git a/core/libdeno/binding.cc b/core/libdeno/binding.cc index 291e62f01..7827cd522 100644 --- a/core/libdeno/binding.cc +++ b/core/libdeno/binding.cc @@ -455,6 +455,16 @@ void EvalContext(const v8::FunctionCallbackInfo& args) { args.GetReturnValue().Set(output); } +void QueueMicrotask(const v8::FunctionCallbackInfo& args) { + v8::Isolate* isolate = args.GetIsolate(); + + if (!(args[0]->IsFunction())) { + ThrowInvalidArgument(isolate); + return; + } + isolate->EnqueueMicrotask(args[0].As()); +} + void InitializeContext(v8::Isolate* isolate, v8::Local context) { v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(context); @@ -493,6 +503,15 @@ void InitializeContext(v8::Isolate* isolate, v8::Local context) { CHECK(core_val->SetAccessor(context, deno::v8_str("shared"), Shared) .FromJust()); + + // Direct bindings on `window`. + auto queue_microtask_tmpl = + v8::FunctionTemplate::New(isolate, QueueMicrotask); + auto queue_microtask_val = + queue_microtask_tmpl->GetFunction(context).ToLocalChecked(); + CHECK( + global->Set(context, deno::v8_str("queueMicrotask"), queue_microtask_val) + .FromJust()); } void MessageCallback(v8::Local message, diff --git a/core/libdeno/internal.h b/core/libdeno/internal.h index 50e85017e..f3789fcc3 100644 --- a/core/libdeno/internal.h +++ b/core/libdeno/internal.h @@ -156,6 +156,7 @@ void ErrorToJSON(const v8::FunctionCallbackInfo& args); void Shared(v8::Local property, const v8::PropertyCallbackInfo& info); void MessageCallback(v8::Local message, v8::Local data); +void QueueMicrotask(const v8::FunctionCallbackInfo& args); static intptr_t external_references[] = { reinterpret_cast(Print), reinterpret_cast(Recv), @@ -164,6 +165,7 @@ static intptr_t external_references[] = { reinterpret_cast(ErrorToJSON), reinterpret_cast(Shared), reinterpret_cast(MessageCallback), + reinterpret_cast(QueueMicrotask), 0}; static const deno_buf empty_buf = {nullptr, 0}; -- cgit v1.2.3