Bug 1615360 - [remote] Add BigInt support to Runtime.callFunctionOn. r=remote-protocol-reviewers,jgraham

Differential Revision: https://phabricator.services.mozilla.com/D64466

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Henrik Skupin 2020-02-27 10:56:48 +00:00
parent 1e0ceaa672
commit 441d61323b
3 changed files with 36 additions and 19 deletions

View File

@ -252,6 +252,7 @@ class ExecutionContext {
}
return this._remoteObjects.get(arg.objectId);
}
if (arg.unserializableValue) {
switch (arg.unserializableValue) {
case "-0":
@ -262,8 +263,15 @@ class ExecutionContext {
return -Infinity;
case "NaN":
return NaN;
default:
if (/^\d+n$/.test(arg.unserializableValue)) {
// eslint-disable-next-line no-undef
return BigInt(arg.unserializableValue.slice(0, -1));
}
throw new Error("Couldn't parse value object in call argument");
}
}
return this._deserialize(arg.value);
}
@ -404,7 +412,10 @@ class ExecutionContext {
unserializableValue = "Infinity";
} else if (Object.is(debuggerObj, -Infinity)) {
unserializableValue = "-Infinity";
} else if (typeof debuggerObj == "bigint") {
unserializableValue = `${debuggerObj}n`;
}
if (unserializableValue) {
return {
type,

View File

@ -141,23 +141,29 @@ async function testReturnByValue({ Runtime }, executionContextId) {
}
// Test non-serializable values
const nonSerializableNumbers = ["-0", "NaN", "Infinity", "-Infinity"];
for (const unserializableValue of nonSerializableNumbers) {
const { result } = await Runtime.callFunctionOn({
executionContextId,
functionDeclaration: "a => a",
arguments: [{ unserializableValue }],
returnByValue: true,
});
Assert.deepEqual(
result,
{
type: "number",
unserializableValue,
description: unserializableValue,
},
"The returned value is the same than the input value"
);
const nonSerializableNumbers = {
number: ["-0", "NaN", "Infinity", "-Infinity"],
bigint: ["42n"],
};
for (const type in nonSerializableNumbers) {
for (const unserializableValue of nonSerializableNumbers[type]) {
const { result } = await Runtime.callFunctionOn({
executionContextId,
functionDeclaration: "a => a",
arguments: [{ unserializableValue }],
returnByValue: true,
});
Assert.deepEqual(
result,
{
type,
unserializableValue,
description: unserializableValue,
},
"The returned value is the same than the input value"
);
}
}
// Test undefined individually as JSON.stringify doesn't return a string

View File

@ -28,7 +28,7 @@ module.exports.addTests = function({testRunner, expect}) {
const result = await page.evaluate(() => 7 * 3);
expect(result).toBe(21);
});
(bigint ? it_fails_ffox : xit)('should transfer BigInt', async({page, server}) => {
(bigint ? it : xit)('should transfer BigInt', async({page, server}) => {
const result = await page.evaluate(a => a, BigInt(42));
expect(result).toBe(BigInt(42));
});
@ -134,7 +134,7 @@ module.exports.addTests = function({testRunner, expect}) {
expect(result).not.toBe(object);
expect(result).toEqual(object);
});
(bigint ? it_fails_ffox : xit)('should return BigInt', async({page, server}) => {
(bigint ? it : xit)('should return BigInt', async({page, server}) => {
const result = await page.evaluate(() => BigInt(42));
expect(result).toBe(BigInt(42));
});