This reverts commit ee203b782c.
References #24040.
Fixes #27181.
This commit is contained in:
parent
ed619b6fcb
commit
c41012b055
|
|
@ -75,10 +75,6 @@ function innerParseSerializedValue(value: SerializedValue, handles: any[] | unde
|
||||||
return BigInt(value.bi);
|
return BigInt(value.bi);
|
||||||
if (value.r !== undefined)
|
if (value.r !== undefined)
|
||||||
return new RegExp(value.r.p, value.r.f);
|
return new RegExp(value.r.p, value.r.f);
|
||||||
if (value.m !== undefined)
|
|
||||||
return new Map(innerParseSerializedValue(value.m, handles, refs));
|
|
||||||
if (value.se !== undefined)
|
|
||||||
return new Set(innerParseSerializedValue(value.se, handles, refs));
|
|
||||||
|
|
||||||
if (value.a !== undefined) {
|
if (value.a !== undefined) {
|
||||||
const result: any[] = [];
|
const result: any[] = [];
|
||||||
|
|
@ -149,10 +145,6 @@ function innerSerializeValue(value: any, handleSerializer: (value: any) => Handl
|
||||||
}
|
}
|
||||||
return { s: `${error.name}: ${error.message}\n${error.stack}` };
|
return { s: `${error.name}: ${error.message}\n${error.stack}` };
|
||||||
}
|
}
|
||||||
if (isMap(value))
|
|
||||||
return { m: innerSerializeValue(Array.from(value), handleSerializer, visitorInfo) };
|
|
||||||
if (isSet(value))
|
|
||||||
return { se: innerSerializeValue(Array.from(value), handleSerializer, visitorInfo) };
|
|
||||||
if (isDate(value))
|
if (isDate(value))
|
||||||
return { d: value.toJSON() };
|
return { d: value.toJSON() };
|
||||||
if (isURL(value))
|
if (isURL(value))
|
||||||
|
|
@ -183,14 +175,6 @@ function innerSerializeValue(value: any, handleSerializer: (value: any) => Handl
|
||||||
throw new Error('Unexpected value');
|
throw new Error('Unexpected value');
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMap(obj: any): obj is Map<any, any> {
|
|
||||||
return obj instanceof Map || Object.prototype.toString.call(obj) === '[object Map]';
|
|
||||||
}
|
|
||||||
|
|
||||||
function isSet(obj: any): obj is Set<any> {
|
|
||||||
return obj instanceof Set || Object.prototype.toString.call(obj) === '[object Set]';
|
|
||||||
}
|
|
||||||
|
|
||||||
function isRegExp(obj: any): obj is RegExp {
|
function isRegExp(obj: any): obj is RegExp {
|
||||||
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
|
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,6 @@ scheme.SerializedValue = tObject({
|
||||||
d: tOptional(tString),
|
d: tOptional(tString),
|
||||||
u: tOptional(tString),
|
u: tOptional(tString),
|
||||||
bi: tOptional(tString),
|
bi: tOptional(tString),
|
||||||
m: tOptional(tType('SerializedValue')),
|
|
||||||
se: tOptional(tType('SerializedValue')),
|
|
||||||
r: tOptional(tObject({
|
r: tOptional(tObject({
|
||||||
p: tString,
|
p: tString,
|
||||||
f: tString,
|
f: tString,
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ export type SerializedValue =
|
||||||
{ d: string } |
|
{ d: string } |
|
||||||
{ u: string } |
|
{ u: string } |
|
||||||
{ bi: string } |
|
{ bi: string } |
|
||||||
{ m: SerializedValue } |
|
|
||||||
{ se: SerializedValue } |
|
|
||||||
{ r: { p: string, f: string} } |
|
{ r: { p: string, f: string} } |
|
||||||
{ a: SerializedValue[], id: number } |
|
{ a: SerializedValue[], id: number } |
|
||||||
{ o: { k: string, v: SerializedValue }[], id: number } |
|
{ o: { k: string, v: SerializedValue }[], id: number } |
|
||||||
|
|
@ -37,14 +35,6 @@ type VisitorInfo = {
|
||||||
|
|
||||||
export function source() {
|
export function source() {
|
||||||
|
|
||||||
function isMap(obj: any): obj is Map<any, any> {
|
|
||||||
return obj instanceof Map || Object.prototype.toString.call(obj) === '[object Map]';
|
|
||||||
}
|
|
||||||
|
|
||||||
function isSet(obj: any): obj is Set<any> {
|
|
||||||
return obj instanceof Set || Object.prototype.toString.call(obj) === '[object Set]';
|
|
||||||
}
|
|
||||||
|
|
||||||
function isRegExp(obj: any): obj is RegExp {
|
function isRegExp(obj: any): obj is RegExp {
|
||||||
try {
|
try {
|
||||||
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
|
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
|
||||||
|
|
@ -104,10 +94,6 @@ export function source() {
|
||||||
return new URL(value.u);
|
return new URL(value.u);
|
||||||
if ('bi' in value)
|
if ('bi' in value)
|
||||||
return BigInt(value.bi);
|
return BigInt(value.bi);
|
||||||
if ('m' in value)
|
|
||||||
return new Map(parseEvaluationResultValue(value.m));
|
|
||||||
if ('se' in value)
|
|
||||||
return new Set(parseEvaluationResultValue(value.se));
|
|
||||||
if ('r' in value)
|
if ('r' in value)
|
||||||
return new RegExp(value.r.p, value.r.f);
|
return new RegExp(value.r.p, value.r.f);
|
||||||
if ('a' in value) {
|
if ('a' in value) {
|
||||||
|
|
@ -177,11 +163,6 @@ export function source() {
|
||||||
if (typeof value === 'bigint')
|
if (typeof value === 'bigint')
|
||||||
return { bi: value.toString() };
|
return { bi: value.toString() };
|
||||||
|
|
||||||
if (isMap(value))
|
|
||||||
return { m: serialize(Array.from(value), handleSerializer, visitorInfo) };
|
|
||||||
if (isSet(value))
|
|
||||||
return { se: serialize(Array.from(value), handleSerializer, visitorInfo) };
|
|
||||||
|
|
||||||
if (isError(value)) {
|
if (isError(value)) {
|
||||||
const error = value;
|
const error = value;
|
||||||
if (error.stack?.startsWith(error.name + ': ' + error.message)) {
|
if (error.stack?.startsWith(error.name + ': ' + error.message)) {
|
||||||
|
|
|
||||||
|
|
@ -180,8 +180,6 @@ export type SerializedValue = {
|
||||||
d?: string,
|
d?: string,
|
||||||
u?: string,
|
u?: string,
|
||||||
bi?: string,
|
bi?: string,
|
||||||
m?: SerializedValue,
|
|
||||||
se?: SerializedValue,
|
|
||||||
r?: {
|
r?: {
|
||||||
p: string,
|
p: string,
|
||||||
f: string,
|
f: string,
|
||||||
|
|
|
||||||
|
|
@ -82,10 +82,6 @@ SerializedValue:
|
||||||
u: string?
|
u: string?
|
||||||
# String representation of BigInt.
|
# String representation of BigInt.
|
||||||
bi: string?
|
bi: string?
|
||||||
# JS representation of Map: [[key1, value1], [key2, value2], ...].
|
|
||||||
m: SerializedValue?
|
|
||||||
# JS representation of Set: [item1, item2, ...].
|
|
||||||
se: SerializedValue?
|
|
||||||
# Regular expression pattern and flags.
|
# Regular expression pattern and flags.
|
||||||
r:
|
r:
|
||||||
type: object?
|
type: object?
|
||||||
|
|
|
||||||
|
|
@ -99,14 +99,9 @@ it('should transfer bigint', async ({ page }) => {
|
||||||
expect(await page.evaluate(a => a, 17n)).toBe(17n);
|
expect(await page.evaluate(a => a, 17n)).toBe(17n);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should transfer maps', async ({ page }) => {
|
it('should transfer maps as empty objects', async ({ page }) => {
|
||||||
expect(await page.evaluate(() => new Map([[1, { test: 42n }]]))).toEqual(new Map([[1, { test: 42n }]]));
|
const result = await page.evaluate(a => a.x.constructor.name + ' ' + JSON.stringify(a.x), { x: new Map([[1, 2]]) });
|
||||||
expect(await page.evaluate(a => a, new Map([[1, { test: 17n }]]))).toEqual(new Map([[1, { test: 17n }]]));
|
expect(result).toBe('Object {}');
|
||||||
});
|
|
||||||
|
|
||||||
it('should transfer sets', async ({ page }) => {
|
|
||||||
expect(await page.evaluate(() => new Set([1, { test: 42n }]))).toEqual(new Set([1, { test: 42n }]));
|
|
||||||
expect(await page.evaluate(a => a, new Set([1, { test: 17n }]))).toEqual(new Set([1, { test: 17n }]));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should modify global environment', async ({ page }) => {
|
it('should modify global environment', async ({ page }) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue