FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: queueMicrotask support by NathanWalker · Pull Request #1868 · NativeScript/android · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .js  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion test-app/app/src/main/assets/app/mainpage.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ require("./tests/testPostFrameCallback");
require("./tests/console/logTests.js");
require('./tests/testURLImpl.js');
require('./tests/testURLSearchParamsImpl.js');
require('./tests/testPerformanceNow');
require('./tests/testPerformanceNow');
require('./tests/testQueueMicrotask');
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe('queueMicrotask', () => {
it('should be defined as a function', () => {
expect(typeof queueMicrotask).toBe('function');
});

it('should throw TypeError when callback is not a function', () => {
expect(() => queueMicrotask(null)).toThrow();
expect(() => queueMicrotask(123)).toThrow();
expect(() => queueMicrotask({})).toThrow();
});

it('runs after current stack but before setTimeout(0)', (done) => {
const order = [];
queueMicrotask(() => order.push('microtask'));
setTimeout(() => {
order.push('timeout');
expect(order).toEqual(['microtask', 'timeout']);
done();
}, 0);
// at this point, nothing should have run yet
expect(order.length).toBe(0);
});

it('preserves ordering with Promise microtasks', (done) => {
const order = [];
queueMicrotask(() => order.push('qm1'));
Promise.resolve().then(() => order.push('p'));
queueMicrotask(() => order.push('qm2'));

setTimeout(() => {
expect(order).toEqual(['qm1', 'p', 'qm2']);
done();
}, 0);
});
});
15 changes: 15 additions & 0 deletions test-app/runtime/src/main/cpp/Runtime.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,21 @@ Isolate* Runtime::PrepareV8Runtime(const string& filesPath, const string& native
performanceTemplate->Set(ArgConverter::ConvertToV8String(isolate, "timeOrigin"), Number::New(isolate, m_realtimeOrigin));
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "performance"), performanceTemplate);
}
// queueMicrotask(callback) per spec: https://developer.mozilla.org/en-US/docs/Web/API/Window/queueMicrotask
globalTemplate->Set(
ArgConverter::ConvertToV8String(isolate, "queueMicrotask"),
FunctionTemplate::New(
isolate,
[](const v8::FunctionCallbackInfo<v8::Value>& info) {
auto* isolate = info.GetIsolate();
if (info.Length() < 1 || !info[0]->IsFunction()) {
isolate->ThrowException(v8::Exception::TypeError(
ArgConverter::ConvertToV8String(isolate, "queueMicrotask: callback must be a function")));
return;
}
v8::Local<v8::Function> cb = info[0].As<v8::Function>();
isolate->EnqueueMicrotask(cb);
}));
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__releaseNativeCounterpart"), FunctionTemplate::New(isolate, CallbackHandlers::ReleaseNativeCounterpartCallback));
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__markingMode"), Number::New(isolate, m_objectManager->GetMarkingMode()), readOnlyFlags);
globalTemplate->Set(ArgConverter::ConvertToV8String(isolate, "__runOnMainThread"), FunctionTemplate::New(isolate, CallbackHandlers::RunOnMainThreadCallback));
Expand Down
Loading

Back | FazBrowse Home | New Git URL