Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(466)

Side by Side Diff: src/isolate.cc

Issue 290633010: Move microtask queueing logic from JavaScript to C++ (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Handle comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.h ('k') | src/object-observe.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #include "v8.h" 7 #include "v8.h"
8 8
9 #include "ast.h" 9 #include "ast.h"
10 #include "bootstrapper.h" 10 #include "bootstrapper.h"
(...skipping 2214 matching lines...) Expand 10 before | Expand all | Expand 10 after
2225 for (int i = 0; i < call_completed_callbacks_.length(); i++) { 2225 for (int i = 0; i < call_completed_callbacks_.length(); i++) {
2226 if (callback == call_completed_callbacks_.at(i)) { 2226 if (callback == call_completed_callbacks_.at(i)) {
2227 call_completed_callbacks_.Remove(i); 2227 call_completed_callbacks_.Remove(i);
2228 } 2228 }
2229 } 2229 }
2230 } 2230 }
2231 2231
2232 2232
2233 void Isolate::FireCallCompletedCallback() { 2233 void Isolate::FireCallCompletedCallback() {
2234 bool has_call_completed_callbacks = !call_completed_callbacks_.is_empty(); 2234 bool has_call_completed_callbacks = !call_completed_callbacks_.is_empty();
2235 bool run_microtasks = autorun_microtasks() && microtask_pending(); 2235 bool run_microtasks = autorun_microtasks() && pending_microtask_count();
2236 if (!has_call_completed_callbacks && !run_microtasks) return; 2236 if (!has_call_completed_callbacks && !run_microtasks) return;
2237 2237
2238 if (!handle_scope_implementer()->CallDepthIsZero()) return; 2238 if (!handle_scope_implementer()->CallDepthIsZero()) return;
2239 if (run_microtasks) RunMicrotasks();
2239 // Fire callbacks. Increase call depth to prevent recursive callbacks. 2240 // Fire callbacks. Increase call depth to prevent recursive callbacks.
2240 handle_scope_implementer()->IncrementCallDepth(); 2241 handle_scope_implementer()->IncrementCallDepth();
2241 if (run_microtasks) Execution::RunMicrotasks(this);
2242 for (int i = 0; i < call_completed_callbacks_.length(); i++) { 2242 for (int i = 0; i < call_completed_callbacks_.length(); i++) {
2243 call_completed_callbacks_.at(i)(); 2243 call_completed_callbacks_.at(i)();
2244 } 2244 }
2245 handle_scope_implementer()->DecrementCallDepth(); 2245 handle_scope_implementer()->DecrementCallDepth();
2246 } 2246 }
2247 2247
2248 2248
2249 void Isolate::EnqueueMicrotask(Handle<JSFunction> microtask) {
2250 Handle<FixedArray> queue(heap()->microtask_queue(), this);
2251 int num_tasks = pending_microtask_count();
2252 ASSERT(num_tasks <= queue->length());
2253 if (num_tasks == 0) {
2254 queue = factory()->NewFixedArray(8);
2255 heap()->set_microtask_queue(*queue);
2256 } else if (num_tasks == queue->length()) {
2257 queue = FixedArray::CopySize(queue, num_tasks * 2);
2258 heap()->set_microtask_queue(*queue);
2259 }
2260 ASSERT(queue->get(num_tasks)->IsUndefined());
2261 queue->set(num_tasks, *microtask);
2262 set_pending_microtask_count(num_tasks + 1);
2263 }
2264
2265
2249 void Isolate::RunMicrotasks() { 2266 void Isolate::RunMicrotasks() {
2250 if (!microtask_pending())
2251 return;
2252
2253 ASSERT(handle_scope_implementer()->CallDepthIsZero()); 2267 ASSERT(handle_scope_implementer()->CallDepthIsZero());
2254 2268
2255 // Increase call depth to prevent recursive callbacks. 2269 // Increase call depth to prevent recursive callbacks.
2256 handle_scope_implementer()->IncrementCallDepth(); 2270 handle_scope_implementer()->IncrementCallDepth();
2257 Execution::RunMicrotasks(this); 2271
2272 while (pending_microtask_count() > 0) {
2273 HandleScope scope(this);
2274 int num_tasks = pending_microtask_count();
2275 Handle<FixedArray> queue(heap()->microtask_queue(), this);
2276 ASSERT(num_tasks <= queue->length());
2277 set_pending_microtask_count(0);
2278 heap()->set_microtask_queue(heap()->empty_fixed_array());
2279
2280 for (int i = 0; i < num_tasks; i++) {
2281 HandleScope scope(this);
2282 Handle<JSFunction> microtask(JSFunction::cast(queue->get(i)), this);
2283 // TODO(adamk): This should ignore/clear exceptions instead of Checking.
2284 Execution::Call(this, microtask, factory()->undefined_value(),
2285 0, NULL).Check();
2286 }
2287 }
2288
2258 handle_scope_implementer()->DecrementCallDepth(); 2289 handle_scope_implementer()->DecrementCallDepth();
2259 } 2290 }
2260 2291
2261 2292
2262 } } // namespace v8::internal 2293 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | src/object-observe.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698