forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promises patch v8 #2
Open
chrisdickinson
wants to merge
3
commits into
promises
Choose a base branch
from
promises-patch-v8
base: promises
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -2642,55 +2642,100 @@ void Isolate::ReportPromiseReject(Handle<JSObject> promise, | |
} | ||
|
||
|
||
void Isolate::ExtEnqueueMicrotask(v8::Local<v8::Function> microtask) { | ||
EnqueueMicrotask(Utils::OpenHandle(*microtask)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not leave this DCHECK in place and drop the abort() call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! Will fix. |
||
microtask_queue()->Enqueue(microtask); | ||
} | ||
|
||
|
||
void Isolate::ExtEnqueueMicrotask(MicrotaskCallback microtask, void* data) { | ||
microtask_queue()->Enqueue(microtask, data); | ||
} | ||
|
||
|
||
void Isolate::EnqueueMicrotask(Handle<Object> microtask) { | ||
DCHECK(microtask->IsJSFunction() || microtask->IsCallHandlerInfo()); | ||
Handle<FixedArray> queue(heap()->microtask_queue(), this); | ||
int num_tasks = pending_microtask_count(); | ||
if (microtask->IsJSFunction()) { | ||
microtask_queue()->Enqueue( | ||
Utils::ToLocal(Handle<JSObject>::cast(microtask)).As<Function>()); | ||
} else { | ||
// panic? | ||
abort(); | ||
} | ||
} | ||
|
||
|
||
#define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ | ||
Handle<Object> foreign = FromCData(obj->GetIsolate(), cdata); \ | ||
(obj)->setter(*foreign); \ | ||
} while (false) | ||
|
||
|
||
void Isolate::DefaultMicrotaskQueue::Enqueue(v8::MicrotaskCallback microtask, void* data) { | ||
HandleScope scope(isolate()); | ||
Handle<CallHandlerInfo> callback_info = | ||
Handle<CallHandlerInfo>::cast( | ||
isolate()->factory()->NewStruct(CALL_HANDLER_INFO_TYPE)); | ||
SET_FIELD_WRAPPED(callback_info, set_callback, microtask); | ||
SET_FIELD_WRAPPED(callback_info, set_data, data); | ||
isolate()->EnqueueMicrotask(callback_info); | ||
} | ||
|
||
|
||
void Isolate::DefaultMicrotaskQueue::Enqueue(Local<v8::Function> microtask) { | ||
Handle<Object> internal_microtask = Utils::OpenHandle(*microtask); | ||
DCHECK(internal_microtask->IsJSFunction() || internal_microtask->IsCallHandlerInfo()); | ||
Handle<FixedArray> queue(isolate()->heap()->microtask_queue(), isolate()); | ||
int num_tasks = isolate()->pending_microtask_count(); | ||
DCHECK(num_tasks <= queue->length()); | ||
if (num_tasks == 0) { | ||
queue = factory()->NewFixedArray(8); | ||
heap()->set_microtask_queue(*queue); | ||
queue = isolate()->factory()->NewFixedArray(8); | ||
isolate()->heap()->set_microtask_queue(*queue); | ||
} else if (num_tasks == queue->length()) { | ||
queue = factory()->CopyFixedArrayAndGrow(queue, num_tasks); | ||
heap()->set_microtask_queue(*queue); | ||
queue = isolate()->factory()->CopyFixedArrayAndGrow(queue, num_tasks); | ||
isolate()->heap()->set_microtask_queue(*queue); | ||
} | ||
DCHECK(queue->get(num_tasks)->IsUndefined()); | ||
queue->set(num_tasks, *microtask); | ||
set_pending_microtask_count(num_tasks + 1); | ||
queue->set(num_tasks, *internal_microtask); | ||
isolate()->set_pending_microtask_count(num_tasks + 1); | ||
} | ||
|
||
|
||
void Isolate::RunMicrotasks() { | ||
microtask_queue()->Run(); | ||
} | ||
|
||
|
||
void Isolate::DefaultMicrotaskQueue::Run() { | ||
// Increase call depth to prevent recursive callbacks. | ||
v8::Isolate::SuppressMicrotaskExecutionScope suppress( | ||
reinterpret_cast<v8::Isolate*>(this)); | ||
reinterpret_cast<v8::Isolate*>(isolate())); | ||
|
||
while (pending_microtask_count() > 0) { | ||
HandleScope scope(this); | ||
int num_tasks = pending_microtask_count(); | ||
Handle<FixedArray> queue(heap()->microtask_queue(), this); | ||
while (isolate()->pending_microtask_count() > 0) { | ||
HandleScope scope(isolate()); | ||
int num_tasks = isolate()->pending_microtask_count(); | ||
Handle<FixedArray> queue(isolate()->heap()->microtask_queue(), isolate()); | ||
DCHECK(num_tasks <= queue->length()); | ||
set_pending_microtask_count(0); | ||
heap()->set_microtask_queue(heap()->empty_fixed_array()); | ||
isolate()->set_pending_microtask_count(0); | ||
isolate()->heap()->set_microtask_queue(isolate()->heap()->empty_fixed_array()); | ||
|
||
for (int i = 0; i < num_tasks; i++) { | ||
HandleScope scope(this); | ||
Handle<Object> microtask(queue->get(i), this); | ||
HandleScope scope(isolate()); | ||
Handle<Object> microtask(queue->get(i), isolate()); | ||
if (microtask->IsJSFunction()) { | ||
Handle<JSFunction> microtask_function = | ||
Handle<JSFunction>::cast(microtask); | ||
SaveContext save(this); | ||
set_context(microtask_function->context()->native_context()); | ||
SaveContext save(isolate()); | ||
isolate()->set_context(microtask_function->context()->native_context()); | ||
MaybeHandle<Object> maybe_exception; | ||
MaybeHandle<Object> result = Execution::TryCall( | ||
this, microtask_function, factory()->undefined_value(), 0, NULL, | ||
isolate(), microtask_function, isolate()->factory()->undefined_value(), 0, NULL, | ||
&maybe_exception); | ||
// If execution is terminating, just bail out. | ||
Handle<Object> exception; | ||
if (result.is_null() && maybe_exception.is_null()) { | ||
// Clear out any remaining callbacks in the queue. | ||
heap()->set_microtask_queue(heap()->empty_fixed_array()); | ||
set_pending_microtask_count(0); | ||
isolate()->heap()->set_microtask_queue(isolate()->heap()->empty_fixed_array()); | ||
isolate()->set_pending_microtask_count(0); | ||
return; | ||
} | ||
} else { | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should explain that using
Isolate::CreateParams
is necessary, in the comments above. Similar to how every other class that makes use ofIsolate::CreateParams
.