Skip to content

Commit

Permalink
cherry-pick(microsoft#27219): Revert "feat(evaluate): serialize map a…
Browse files Browse the repository at this point in the history
…nd set (microsoft#26730)"

This reverts commit ee203b7.

References microsoft#24040.
Fixes microsoft#27181.
  • Loading branch information
dgozman committed Sep 21, 2023
1 parent ed619b6 commit bc675c8
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 51 deletions.
16 changes: 0 additions & 16 deletions packages/playwright-core/src/protocol/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ function innerParseSerializedValue(value: SerializedValue, handles: any[] | unde
return BigInt(value.bi);
if (value.r !== undefined)
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) {
const result: any[] = [];
Expand Down Expand Up @@ -149,10 +145,6 @@ function innerSerializeValue(value: any, handleSerializer: (value: any) => Handl
}
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))
return { d: value.toJSON() };
if (isURL(value))
Expand Down Expand Up @@ -183,14 +175,6 @@ function innerSerializeValue(value: any, handleSerializer: (value: any) => Handl
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 {
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
}
Expand Down
2 changes: 0 additions & 2 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ scheme.SerializedValue = tObject({
d: tOptional(tString),
u: tOptional(tString),
bi: tOptional(tString),
m: tOptional(tType('SerializedValue')),
se: tOptional(tType('SerializedValue')),
r: tOptional(tObject({
p: tString,
f: tString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export type SerializedValue =
{ d: string } |
{ u: string } |
{ bi: string } |
{ m: SerializedValue } |
{ se: SerializedValue } |
{ r: { p: string, f: string} } |
{ a: SerializedValue[], id: number } |
{ o: { k: string, v: SerializedValue }[], id: number } |
Expand All @@ -37,14 +35,6 @@ type VisitorInfo = {

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 {
try {
return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
Expand Down Expand Up @@ -104,10 +94,6 @@ export function source() {
return new URL(value.u);
if ('bi' in value)
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)
return new RegExp(value.r.p, value.r.f);
if ('a' in value) {
Expand Down Expand Up @@ -177,11 +163,6 @@ export function source() {
if (typeof value === 'bigint')
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)) {
const error = value;
if (error.stack?.startsWith(error.name + ': ' + error.message)) {
Expand Down
2 changes: 0 additions & 2 deletions packages/protocol/src/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ export type SerializedValue = {
d?: string,
u?: string,
bi?: string,
m?: SerializedValue,
se?: SerializedValue,
r?: {
p: string,
f: string,
Expand Down
4 changes: 0 additions & 4 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ SerializedValue:
u: string?
# String representation of BigInt.
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.
r:
type: object?
Expand Down
11 changes: 3 additions & 8 deletions tests/page/page-evaluate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,9 @@ it('should transfer bigint', async ({ page }) => {
expect(await page.evaluate(a => a, 17n)).toBe(17n);
});

it('should transfer maps', async ({ page }) => {
expect(await page.evaluate(() => new Map([[1, { test: 42n }]]))).toEqual(new Map([[1, { test: 42n }]]));
expect(await page.evaluate(a => a, new Map([[1, { test: 17n }]]))).toEqual(new Map([[1, { test: 17n }]]));
});

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 transfer maps as empty objects', async ({ page }) => {
const result = await page.evaluate(a => a.x.constructor.name + ' ' + JSON.stringify(a.x), { x: new Map([[1, 2]]) });
expect(result).toBe('Object {}');
});

it('should modify global environment', async ({ page }) => {
Expand Down

0 comments on commit bc675c8

Please sign in to comment.