| OLD | NEW |
| (Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspecto
r-protocol-test.js"></script> |
| 4 <script> |
| 5 |
| 6 function createPromiseAndScheduleResolve() |
| 7 { |
| 8 var resolveCallback; |
| 9 var promise = new Promise((resolve) => resolveCallback = resolve); |
| 10 setTimeout(resolveCallback.bind(null, { a : 239 }), 0); |
| 11 return promise; |
| 12 } |
| 13 |
| 14 function test() |
| 15 { |
| 16 InspectorTest.runTestSuite([ |
| 17 function testArguments(next) |
| 18 { |
| 19 callFunctionOn( |
| 20 "({a : 1})", |
| 21 "function(arg1, arg2, arg3, arg4) { return \"\" + arg1 + \"|\" +
arg2 + \"|\" + arg3 + \"|\" + arg4; }", |
| 22 [ "undefined", "NaN", "({a:2})", "window"], |
| 23 /* returnByValue */ true, |
| 24 /* generatePreview */ false, |
| 25 /* awaitPromise */ false) |
| 26 .then((result) => dumpResult(result.result)) |
| 27 .then(() => next()); |
| 28 }, |
| 29 |
| 30 function testSyntaxErrorInFunction(next) |
| 31 { |
| 32 callFunctionOn( |
| 33 "({a : 1})", |
| 34 "\n }", |
| 35 [], |
| 36 /* returnByValue */ false, |
| 37 /* generatePreview */ false, |
| 38 /* awaitPromise */ true) |
| 39 .then((result) => dumpResult(result.result)) |
| 40 .then(() => next()); |
| 41 }, |
| 42 |
| 43 function testExceptionInFunctionExpression(next) |
| 44 { |
| 45 callFunctionOn( |
| 46 "({a : 1})", |
| 47 "(function() { throw new Error() })()", |
| 48 [], |
| 49 /* returnByValue */ false, |
| 50 /* generatePreview */ false, |
| 51 /* awaitPromise */ true) |
| 52 .then((result) => dumpResult(result.result)) |
| 53 .then(() => next()); |
| 54 }, |
| 55 |
| 56 function testFunctionReturnNotPromise(next) |
| 57 { |
| 58 callFunctionOn( |
| 59 "({a : 1})", |
| 60 "(function() { return 239; })", |
| 61 [], |
| 62 /* returnByValue */ false, |
| 63 /* generatePreview */ false, |
| 64 /* awaitPromise */ true) |
| 65 .then((result) => InspectorTest.logObject(result.error)) |
| 66 .then(() => next()); |
| 67 }, |
| 68 |
| 69 function testFunctionReturnResolvedPromiseReturnByValue(next) |
| 70 { |
| 71 callFunctionOn( |
| 72 "({a : 1})", |
| 73 "(function(arg) { return Promise.resolve({a : this.a + arg.a});
})", |
| 74 [ "({a:2})" ], |
| 75 /* returnByValue */ true, |
| 76 /* generatePreview */ false, |
| 77 /* awaitPromise */ true) |
| 78 .then((result) => dumpResult(result.result)) |
| 79 .then(() => next()); |
| 80 }, |
| 81 |
| 82 function testFunctionReturnResolvedPromiseWithPreview(next) |
| 83 { |
| 84 callFunctionOn( |
| 85 "({a : 1})", |
| 86 "(function(arg) { return Promise.resolve({a : this.a + arg.a});
})", |
| 87 [ "({a:2})" ], |
| 88 /* returnByValue */ false, |
| 89 /* generatePreview */ true, |
| 90 /* awaitPromise */ true) |
| 91 .then((result) => dumpResult(result.result)) |
| 92 .then(() => next()); |
| 93 }, |
| 94 |
| 95 function testFunctionReturnRejectedPromise(next) |
| 96 { |
| 97 callFunctionOn( |
| 98 "({a : 1})", |
| 99 "(function(arg) { return Promise.reject({a : this.a + arg.a}); }
)", |
| 100 [ "({a:2})" ], |
| 101 /* returnByValue */ true, |
| 102 /* generatePreview */ false, |
| 103 /* awaitPromise */ true) |
| 104 .then((result) => dumpResult(result.result)) |
| 105 .then(() => next()); |
| 106 } |
| 107 ]); |
| 108 |
| 109 function callFunctionOn(objectExpression, functionDeclaration, argumentExpre
ssions, returnByValue, generatePreview, awaitPromise) |
| 110 { |
| 111 var objectId; |
| 112 var callArguments = []; |
| 113 var promise = InspectorTest.sendCommandPromise("Runtime.evaluate", { exp
ression: objectExpression }) |
| 114 .then((result) => objectId = result.result.result.objectId) |
| 115 for (let argumentExpression of argumentExpressions) { |
| 116 promise = promise |
| 117 .then(() => InspectorTest.sendCommandPromise("Runtime.evaluate",
{ expression: argumentExpression })) |
| 118 .then((result) => addArgument(result.result.result)); |
| 119 } |
| 120 return promise.then(() => InspectorTest.sendCommandPromise("Runtime.call
FunctionOn", { objectId: objectId, functionDeclaration: functionDeclaration, arg
uments: callArguments, returnByValue: returnByValue, generatePreview: generatePr
eview, awaitPromise: awaitPromise })); |
| 121 |
| 122 function addArgument(result) |
| 123 { |
| 124 if (result.objectId) |
| 125 callArguments.push({ objectId: result.objectId, type: result.typ
e }); |
| 126 else if (result.value) |
| 127 callArguments.push({ value: result.value, type: result.type }) |
| 128 else |
| 129 callArguments.push({ type: result.type }); |
| 130 } |
| 131 } |
| 132 |
| 133 function dumpResult(result) |
| 134 { |
| 135 if (result.exceptionDetails && result.exceptionDetails.scriptId) |
| 136 result.exceptionDetails.scriptId = 0; |
| 137 if (result.result && result.result.objectId) |
| 138 result.result.objectId = "[ObjectId]"; |
| 139 InspectorTest.logObject(result); |
| 140 } |
| 141 } |
| 142 </script> |
| 143 </head> |
| 144 <body onLoad="runTest();"> |
| 145 Tests that Runtime.callFunctionOn works with awaitPromise flag. |
| 146 </body> |
| 147 </html> |
| 148 |
| OLD | NEW |