diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-08-31 12:16:30 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-08-31 15:16:30 -0400 |
commit | fdd4252d49ceb022761b92d953d24672ab67ab91 (patch) | |
tree | 2c4e3517339bef1ead257c427f6073dcbc7db604 /core/libdeno/binding.cc | |
parent | 07c3c76d0d7585dc49ffde79d38c406ca9f6e7ca (diff) |
Add window.queueMicrotask (#2844)
Diffstat (limited to 'core/libdeno/binding.cc')
-rw-r--r-- | core/libdeno/binding.cc | 19 |
1 files changed, 19 insertions, 0 deletions
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<v8::Value>& args) { args.GetReturnValue().Set(output); } +void QueueMicrotask(const v8::FunctionCallbackInfo<v8::Value>& args) { + v8::Isolate* isolate = args.GetIsolate(); + + if (!(args[0]->IsFunction())) { + ThrowInvalidArgument(isolate); + return; + } + isolate->EnqueueMicrotask(args[0].As<v8::Function>()); +} + void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> context) { v8::HandleScope handle_scope(isolate); v8::Context::Scope context_scope(context); @@ -493,6 +503,15 @@ void InitializeContext(v8::Isolate* isolate, v8::Local<v8::Context> 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<v8::Message> message, |