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

Side by Side Diff: Source/bindings/v8/custom/V8PromiseCustom.cpp

Issue 18648011: Implement Promise.fulfill, Promise.resolve and Promise.reject. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 7 years, 5 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
« no previous file with comments | « LayoutTests/fast/js/Promise-static-resolve-expected.txt ('k') | Source/core/dom/Promise.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 v8::Local<v8::Object> environment = wrapperCallbackEnvironment(promise, resolver, args[0].As<v8::Function>()); 382 v8::Local<v8::Object> environment = wrapperCallbackEnvironment(promise, resolver, args[0].As<v8::Function>());
383 rejectWrapper = v8::FunctionTemplate::New(wrapperCallback, environment)- >GetFunction(); 383 rejectWrapper = v8::FunctionTemplate::New(wrapperCallback, environment)- >GetFunction();
384 } else { 384 } else {
385 rejectWrapper = promiseCallback(resolver, V8PromiseCustom::RejectAlgorit hm, isolate); 385 rejectWrapper = promiseCallback(resolver, V8PromiseCustom::RejectAlgorit hm, isolate);
386 } 386 }
387 fulfillWrapper = promiseCallback(resolver, V8PromiseCustom::FulfillAlgorithm , isolate); 387 fulfillWrapper = promiseCallback(resolver, V8PromiseCustom::FulfillAlgorithm , isolate);
388 V8PromiseCustom::append(args.Holder(), fulfillWrapper, rejectWrapper, isolat e); 388 V8PromiseCustom::append(args.Holder(), fulfillWrapper, rejectWrapper, isolat e);
389 v8SetReturnValue(args, promise); 389 v8SetReturnValue(args, promise);
390 } 390 }
391 391
392 void V8Promise::fulfillMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& a rgs)
393 {
394 v8::Isolate* isolate = args.GetIsolate();
395 v8::Local<v8::Value> result = v8::Undefined(isolate);
396 if (args.Length() > 0)
397 result = args[0];
398
399 v8::Local<v8::Object> promise, resolver;
400 V8PromiseCustom::createPromise(args.Holder(), &promise, &resolver, isolate);
401 V8PromiseCustom::fulfillResolver(resolver, result, V8PromiseCustom::Asynchro nous, isolate);
402 v8SetReturnValue(args, promise);
403 }
404
405 void V8Promise::resolveMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& a rgs)
406 {
407 v8::Isolate* isolate = args.GetIsolate();
408 v8::Local<v8::Value> result = v8::Undefined(isolate);
409 if (args.Length() > 0)
410 result = args[0];
411
412 v8::Local<v8::Object> promise, resolver;
413 V8PromiseCustom::createPromise(args.Holder(), &promise, &resolver, isolate);
414 V8PromiseCustom::resolveResolver(resolver, result, V8PromiseCustom::Asynchro nous, isolate);
415 v8SetReturnValue(args, promise);
416 }
417
418 void V8Promise::rejectMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& ar gs)
419 {
420 v8::Isolate* isolate = args.GetIsolate();
421 v8::Local<v8::Value> result = v8::Undefined(isolate);
422 if (args.Length() > 0)
423 result = args[0];
424
425 v8::Local<v8::Object> promise, resolver;
426 V8PromiseCustom::createPromise(args.Holder(), &promise, &resolver, isolate);
427 V8PromiseCustom::rejectResolver(resolver, result, V8PromiseCustom::Asynchron ous, isolate);
428 v8SetReturnValue(args, promise);
429 }
430
392 void V8Promise::anyMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) 431 void V8Promise::anyMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args)
393 { 432 {
394 v8::Isolate* isolate = args.GetIsolate(); 433 v8::Isolate* isolate = args.GetIsolate();
395 v8::Local<v8::Object> promise, resolver; 434 v8::Local<v8::Object> promise, resolver;
396 V8PromiseCustom::createPromise(args.Holder(), &promise, &resolver, isolate); 435 V8PromiseCustom::createPromise(args.Holder(), &promise, &resolver, isolate);
397 436
398 if (!args.Length()) { 437 if (!args.Length()) {
399 V8PromiseCustom::resolveResolver(resolver, v8::Undefined(isolate), V8Pro miseCustom::Asynchronous, isolate); 438 V8PromiseCustom::resolveResolver(resolver, v8::Undefined(isolate), V8Pro miseCustom::Asynchronous, isolate);
400 v8SetReturnValue(args, promise); 439 v8SetReturnValue(args, promise);
401 return; 440 return;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 v8::TryCatch trycatch; 671 v8::TryCatch trycatch;
633 v8::Handle<v8::Value> args[] = { result }; 672 v8::Handle<v8::Value> args[] = { result };
634 V8ScriptRunner::callFunction(function, getScriptExecutionContext(), rece iver, WTF_ARRAY_LENGTH(args), args); 673 V8ScriptRunner::callFunction(function, getScriptExecutionContext(), rece iver, WTF_ARRAY_LENGTH(args), args);
635 } else { 674 } else {
636 ASSERT(mode == Asynchronous); 675 ASSERT(mode == Asynchronous);
637 postTask(function, receiver, result, isolate); 676 postTask(function, receiver, result, isolate);
638 } 677 }
639 } 678 }
640 679
641 } // namespace WebCore 680 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/js/Promise-static-resolve-expected.txt ('k') | Source/core/dom/Promise.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698