OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 print("Tests that Runtime.callFunctionOn works with awaitPromise flag."); | 5 print("Tests that Runtime.callFunctionOn works with awaitPromise flag."); |
6 | 6 |
7 InspectorTest.runTestSuite([ | 7 InspectorTest.runTestSuite([ |
8 function testArguments(next) | 8 function testArguments(next) |
9 { | 9 { |
10 callFunctionOn( | 10 callFunctionOn( |
11 "({a : 1})", | 11 "({a : 1})", |
12 "function(arg1, arg2, arg3, arg4) { return \"\" + arg1 + \"|\" + arg2 + \"
|\" + arg3 + \"|\" + arg4; }", | 12 "function(arg1, arg2, arg3, arg4) { return \"\" + arg1 + \"|\" + arg2 + \"
|\" + arg3 + \"|\" + arg4; }", |
13 [ "undefined", "NaN", "({a:2})", "this"], | 13 [ "undefined", "NaN", "({a:2})", "this"], |
14 /* returnByValue */ true, | 14 /* returnByValue */ true, |
15 /* generatePreview */ false, | 15 /* generatePreview */ false, |
16 /* awaitPromise */ false) | 16 /* awaitPromise */ false) |
17 .then((result) => dumpResult(result.result)) | 17 .then((result) => InspectorTest.logMessage(result)) |
18 .then(() => next()); | 18 .then(() => next()); |
19 }, | 19 }, |
20 | 20 |
21 function testSyntaxErrorInFunction(next) | 21 function testSyntaxErrorInFunction(next) |
22 { | 22 { |
23 callFunctionOn( | 23 callFunctionOn( |
24 "({a : 1})", | 24 "({a : 1})", |
25 "\n }", | 25 "\n }", |
26 [], | 26 [], |
27 /* returnByValue */ false, | 27 /* returnByValue */ false, |
28 /* generatePreview */ false, | 28 /* generatePreview */ false, |
29 /* awaitPromise */ true) | 29 /* awaitPromise */ true) |
30 .then((result) => dumpResult(result.result)) | 30 .then((result) => InspectorTest.logMessage(result)) |
31 .then(() => next()); | 31 .then(() => next()); |
32 }, | 32 }, |
33 | 33 |
34 function testExceptionInFunctionExpression(next) | 34 function testExceptionInFunctionExpression(next) |
35 { | 35 { |
36 callFunctionOn( | 36 callFunctionOn( |
37 "({a : 1})", | 37 "({a : 1})", |
38 "(function() { throw new Error() })()", | 38 "(function() { throw new Error() })()", |
39 [], | 39 [], |
40 /* returnByValue */ false, | 40 /* returnByValue */ false, |
41 /* generatePreview */ false, | 41 /* generatePreview */ false, |
42 /* awaitPromise */ true) | 42 /* awaitPromise */ true) |
43 .then((result) => dumpResult(result.result)) | 43 .then((result) => InspectorTest.logMessage(result)) |
44 .then(() => next()); | 44 .then(() => next()); |
45 }, | 45 }, |
46 | 46 |
47 function testFunctionReturnNotPromise(next) | 47 function testFunctionReturnNotPromise(next) |
48 { | 48 { |
49 callFunctionOn( | 49 callFunctionOn( |
50 "({a : 1})", | 50 "({a : 1})", |
51 "(function() { return 239; })", | 51 "(function() { return 239; })", |
52 [], | 52 [], |
53 /* returnByValue */ false, | 53 /* returnByValue */ false, |
54 /* generatePreview */ false, | 54 /* generatePreview */ false, |
55 /* awaitPromise */ true) | 55 /* awaitPromise */ true) |
56 .then((result) => InspectorTest.logObject(result.error)) | 56 .then((result) => InspectorTest.logMessage(result.error)) |
57 .then(() => next()); | 57 .then(() => next()); |
58 }, | 58 }, |
59 | 59 |
60 function testFunctionReturnResolvedPromiseReturnByValue(next) | 60 function testFunctionReturnResolvedPromiseReturnByValue(next) |
61 { | 61 { |
62 callFunctionOn( | 62 callFunctionOn( |
63 "({a : 1})", | 63 "({a : 1})", |
64 "(function(arg) { return Promise.resolve({a : this.a + arg.a}); })", | 64 "(function(arg) { return Promise.resolve({a : this.a + arg.a}); })", |
65 [ "({a:2})" ], | 65 [ "({a:2})" ], |
66 /* returnByValue */ true, | 66 /* returnByValue */ true, |
67 /* generatePreview */ false, | 67 /* generatePreview */ false, |
68 /* awaitPromise */ true) | 68 /* awaitPromise */ true) |
69 .then((result) => dumpResult(result.result)) | 69 .then((result) => InspectorTest.logMessage(result)) |
70 .then(() => next()); | 70 .then(() => next()); |
71 }, | 71 }, |
72 | 72 |
73 function testFunctionReturnResolvedPromiseWithPreview(next) | 73 function testFunctionReturnResolvedPromiseWithPreview(next) |
74 { | 74 { |
75 callFunctionOn( | 75 callFunctionOn( |
76 "({a : 1})", | 76 "({a : 1})", |
77 "(function(arg) { return Promise.resolve({a : this.a + arg.a}); })", | 77 "(function(arg) { return Promise.resolve({a : this.a + arg.a}); })", |
78 [ "({a:2})" ], | 78 [ "({a:2})" ], |
79 /* returnByValue */ false, | 79 /* returnByValue */ false, |
80 /* generatePreview */ true, | 80 /* generatePreview */ true, |
81 /* awaitPromise */ true) | 81 /* awaitPromise */ true) |
82 .then((result) => dumpResult(result.result)) | 82 .then((result) => InspectorTest.logMessage(result)) |
83 .then(() => next()); | 83 .then(() => next()); |
84 }, | 84 }, |
85 | 85 |
86 function testFunctionReturnRejectedPromise(next) | 86 function testFunctionReturnRejectedPromise(next) |
87 { | 87 { |
88 callFunctionOn( | 88 callFunctionOn( |
89 "({a : 1})", | 89 "({a : 1})", |
90 "(function(arg) { return Promise.reject({a : this.a + arg.a}); })", | 90 "(function(arg) { return Promise.reject({a : this.a + arg.a}); })", |
91 [ "({a:2})" ], | 91 [ "({a:2})" ], |
92 /* returnByValue */ true, | 92 /* returnByValue */ true, |
93 /* generatePreview */ false, | 93 /* generatePreview */ false, |
94 /* awaitPromise */ true) | 94 /* awaitPromise */ true) |
95 .then((result) => dumpResult(result.result)) | 95 .then((result) => InspectorTest.logMessage(result)) |
96 .then(() => next()); | 96 .then(() => next()); |
97 } | 97 } |
98 ]); | 98 ]); |
99 | 99 |
100 function callFunctionOn(objectExpression, functionDeclaration, argumentExpressio
ns, returnByValue, generatePreview, awaitPromise) | 100 function callFunctionOn(objectExpression, functionDeclaration, argumentExpressio
ns, returnByValue, generatePreview, awaitPromise) |
101 { | 101 { |
102 var objectId; | 102 var objectId; |
103 var callArguments = []; | 103 var callArguments = []; |
104 var promise = InspectorTest.sendCommandPromise("Runtime.evaluate", { expressio
n: objectExpression }) | 104 var promise = Protocol.Runtime.evaluate({ expression: objectExpression }) |
105 .then((result) => objectId = result.result.result.objectId) | 105 .then((result) => objectId = result.result.result.objectId) |
106 for (let argumentExpression of argumentExpressions) { | 106 for (let argumentExpression of argumentExpressions) { |
107 promise = promise | 107 promise = promise |
108 .then(() => InspectorTest.sendCommandPromise("Runtime.evaluate", { express
ion: argumentExpression })) | 108 .then(() => Protocol.Runtime.evaluate({ expression: argumentExpression })) |
109 .then((result) => addArgument(result.result.result)); | 109 .then((result) => addArgument(result.result.result)); |
110 } | 110 } |
111 return promise.then(() => InspectorTest.sendCommandPromise("Runtime.callFuncti
onOn", { objectId: objectId, functionDeclaration: functionDeclaration, arguments
: callArguments, returnByValue: returnByValue, generatePreview: generatePreview,
awaitPromise: awaitPromise })); | 111 return promise.then(() => Protocol.Runtime.callFunctionOn({ objectId: objectId
, functionDeclaration: functionDeclaration, arguments: callArguments, returnByVa
lue: returnByValue, generatePreview: generatePreview, awaitPromise: awaitPromise
})); |
112 | 112 |
113 function addArgument(result) | 113 function addArgument(result) |
114 { | 114 { |
115 if (result.objectId) { | 115 if (result.objectId) { |
116 callArguments.push({ objectId: result.objectId }); | 116 callArguments.push({ objectId: result.objectId }); |
117 } else if (result.value) { | 117 } else if (result.value) { |
118 callArguments.push({ value: result.value }) | 118 callArguments.push({ value: result.value }) |
119 } else if (result.unserializableValue) { | 119 } else if (result.unserializableValue) { |
120 callArguments.push({ unserializableValue: result.unserializableValue }); | 120 callArguments.push({ unserializableValue: result.unserializableValue }); |
121 } else if (result.type === "undefined") { | 121 } else if (result.type === "undefined") { |
122 callArguments.push({}); | 122 callArguments.push({}); |
123 } else { | 123 } else { |
124 InspectorTest.log("Unexpected argument object:"); | 124 InspectorTest.log("Unexpected argument object:"); |
125 InspectorTest.logObject(result); | 125 InspectorTest.logMessage(result); |
126 InspectorTest.completeTest(); | 126 InspectorTest.completeTest(); |
127 } | 127 } |
128 } | 128 } |
129 } | 129 } |
130 | |
131 function dumpResult(result) | |
132 { | |
133 if (result.exceptionDetails && result.exceptionDetails.scriptId) | |
134 result.exceptionDetails.scriptId = 0; | |
135 if (result.result && result.result.objectId) | |
136 result.result.objectId = "[ObjectId]"; | |
137 if (result.exceptionDetails) { | |
138 result.exceptionDetails.exceptionId = 0; | |
139 result.exceptionDetails.exception.objectId = 0; | |
140 } | |
141 InspectorTest.logObject(result); | |
142 } | |
OLD | NEW |