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

Unified Diff: LayoutTests/fast/js/Promise-bindings-check-exception.html

Issue 232563003: API functions returning Promises should not throw exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/js/Promise-bindings-check-exception.html
diff --git a/LayoutTests/fast/js/Promise-bindings-check-exception.html b/LayoutTests/fast/js/Promise-bindings-check-exception.html
new file mode 100644
index 0000000000000000000000000000000000000000..d363ce581a1783510a44cde5017d1a972396a9b9
--- /dev/null
+++ b/LayoutTests/fast/js/Promise-bindings-check-exception.html
@@ -0,0 +1,89 @@
+<!DOCTYPE html>
+<html>
Nils Barth (inactive) 2014/04/10 10:02:47 nit: <html>, <head>, and <body> can all be omitted
yhirano 2014/04/11 10:19:04 Done.
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description('Test whether the generated code handles exceptions correctly.');
Nils Barth (inactive) 2014/04/10 10:02:47 generated *bindings* ? Also, perhaps linking to th
yhirano 2014/04/11 10:19:04 Done.
+
+window.jsTestIsAsync = true;
+
+var reason;
+
+function shouldBeRejected(promise, message) {
+ return promise.then(function() {
eroman 2014/04/10 09:28:15 nit; should the javascript indentation be 4 spaces
yhirano 2014/04/11 10:19:04 Done.
+ testFailed('Resolved unexpectedly: ' + message);
+ }, function(e) {
+ reason = e;
+ testPassed('Rejected as expected: ' + message);
+ shouldBeTrue('reason instanceof Error');
+ debug(e);
+ });
+}
+
+function shouldBeResolved(promise, message) {
+ return promise.then(function() {
+ testPassed('Resolved as expected: ' + message);
+ }, function(e) {
+ testFailed('Rejected unexpectedly: ' + message);
+ reason = e;
+ shouldBeTrue('reason instanceof Error');
+ debug(e);
+ });
+}
+
+var check = internals.promiseCheck.bind(internals);
+var check2 = internals.promiseCheckWithoutExceptionState.bind(internals);
+var check3 = internals.promiseCheckRange.bind(internals);
+
+Promise.resolve().then(function() {
+ return shouldBeRejected(check(), 'no arguments');
+}).then(function() {
+ return shouldBeResolved(check(3, true, {}, ''), 'valid arguments');
+}).then(function() {
+ return shouldBeResolved(check(null, true, {}, ''), 'convert(long)');
+}).then(function() {
+ return shouldBeResolved(check(3, {}, {}, ''), 'convert(boolean)');
+}).then(function() {
+ return shouldBeRejected(check(3, true, 3, ''), 'type error(Dictionary)');
+}).then(function() {
+ return shouldBeResolved(check(3, true, {}, {}), 'convert(String)');
+}).then(function() {
+ var x = {
+ toString: function() {
+ throw Error('Thrown from toString');
+ }
+ };
+ return shouldBeRejected(check(3, true, {}, x), 'conversion error(toString)');
+}).then(function() {
+ return shouldBeRejected(check(3, false, {}, ''), 'rejected by the impl');
+}).then(function() {
+ return shouldBeRejected(check2(), 'no arguments');
+}).then(function() {
+ return shouldBeResolved(check2({}, '', '', ''), 'valid arguments');
+}).then(function() {
+ return shouldBeResolved(check2({}, ''), 'valid arguments');
+}).then(function() {
+ return shouldBeRejected(check2(3, ''), 'type error(Dictionary)');
+}).then(function() {
+ return shouldBeResolved(check2({}, '', {}, 3), 'convert(String...)');
+}).then(function() {
+ var x = {
+ toString: function() {
+ throw Error('Thrown from toString');
+ }
+ };
+ return shouldBeRejected(check2({}, '', '', x), 'conversion error(String...)');
+}).then(function() {
+ return shouldBeRejected(check3(-1), 'range error(octet)');
+}).then(undefined, function(e) {
+ testFailed('An exception is thrown from a method');
+ debug(e);
+}).then(finishJSTest, finishJSTest);
+
Nils Barth (inactive) 2014/04/10 10:02:47 ? Trailing newline ?
yhirano 2014/04/11 10:19:04 Done.
+</script>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/fast/js/Promise-bindings-check-exception-expected.txt » ('j') | Source/bindings/v8/ExceptionState.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698