Commit b61ee5f3 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[web snapshot] Support static methods, static async methods,

... static generator methods and static async generator methods
for Class.

Bug: v8:11525
Change-Id: I58e8059c95e8a24e1a09d84aea84b82d35f5e2d7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3688891
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81058}
parent b3d004aa
......@@ -125,6 +125,10 @@ uint32_t WebSnapshotSerializerDeserializer::FunctionKindToFunctionFlags(
case FunctionKind::kDefaultDerivedConstructor:
case FunctionKind::kConciseMethod:
case FunctionKind::kAsyncConciseMethod:
case FunctionKind::kStaticConciseMethod:
case FunctionKind::kStaticAsyncConciseMethod:
case FunctionKind::kStaticConciseGeneratorMethod:
case FunctionKind::kStaticAsyncConciseGeneratorMethod:
break;
default:
Throw("Unsupported function kind");
......@@ -183,17 +187,11 @@ FunctionKind WebSnapshotSerializerDeserializer::FunctionFlagsToFunctionKind(
// kStaticMethod
// is_generator = false
// TODO(v8::11525) Support FunctionKind::kStaticConciseMethod.
FunctionKind::kInvalid, // is_async = false
// TODO(v8::11525) Support FunctionKind::kStaticAsyncConciseMethod.
FunctionKind::kInvalid, // is_async = true
FunctionKind::kStaticConciseMethod, // is_async = false
FunctionKind::kStaticAsyncConciseMethod, // is_async = true
// is_generator = true
// TODO(v8::11525) Support
// FunctionKind::kStaticConciseGeneratorMethod.
FunctionKind::kInvalid, // is_async = false
// TODO(v8::11525) Support
// FunctionKind::kStaticAsyncConciseGeneratorMethod.
FunctionKind::kInvalid // is_async = true
FunctionKind::kStaticConciseGeneratorMethod, // is_async = false
FunctionKind::kStaticAsyncConciseGeneratorMethod // is_async = true
};
kind = kFunctionKinds[index];
}
......
......@@ -83,14 +83,14 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
(function TestClassWithProperties() {
function createObjects() {
globalThis.Foo = class Foo { };
Foo.key1 = "value1";
Foo.key1 = 'value1';
Foo.key2 = 1;
Foo.key3 = 2.2;
Foo.key4 = function key4() {
return "key4";
return 'key4';
}
Foo.key5 = [1, 2];
Foo.key6 = {"key":"value"}
Foo.key6 = {'key':'value'}
}
const { Foo } = takeAndUseWebSnapshot(createObjects, ['Foo']);
assertEquals('value1', Foo.key1);
......@@ -98,17 +98,17 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertEquals(2.2, Foo.key3);
assertEquals('key4', Foo.key4());
assertEquals([1, 2], Foo.key5);
assertEquals({ "key": "value" }, Foo.key6 );
assertEquals({ 'key': 'value' }, Foo.key6 );
})();
(function TestClassWithStaticProperties() {
function createObjects() {
globalThis.Foo = class Foo {
static key1 = "value1";
static key1 = 'value1';
static key2 = 1;
static key3 = 2.2;
static key4 = [1, 2];
static key5 = {"key":"value"}
static key5 = {'key':'value'}
};
}
const { Foo } = takeAndUseWebSnapshot(createObjects, ['Foo']);
......@@ -116,5 +116,62 @@ d8.file.execute('test/mjsunit/web-snapshot/web-snapshot-helpers.js');
assertEquals(1, Foo.key2);
assertEquals(2.2, Foo.key3);
assertEquals([1, 2], Foo.key4);
assertEquals({ "key": "value" }, Foo.key5 );
assertEquals({ 'key': 'value' }, Foo.key5 );
})();
(function TestClassWithStaticMethods() {
function createObjects() {
globalThis.Foo = class Foo {
static foo() {
return 'foo'
}
};
}
const { Foo } = takeAndUseWebSnapshot(createObjects, ['Foo']);
assertEquals('foo', Foo.foo());
})();
(async function TestClassWithStaticAsyncMethods() {
function createObjects() {
globalThis.Foo = class Foo {
static async foo() {
await Promise.resolve(1);
return 'foo'
}
};
}
const { Foo } = takeAndUseWebSnapshot(createObjects, ['Foo']);
assertEquals('foo', await Foo.foo());
})();
(function TestClassWithStaticGeneratorMethods() {
function createObjects() {
globalThis.Foo = class Foo {
static *foo() {
yield 'foo1'
return 'foo2'
}
};
}
const { Foo } = takeAndUseWebSnapshot(createObjects, ['Foo']);
const foo = Foo.foo()
assertEquals('foo1', foo.next().value);
assertEquals('foo2', foo.next().value);
assertEquals(true, foo.next().done);
})();
(async function TestClassWithStaticAsyncGeneratorMethods() {
function createObjects() {
globalThis.Foo = class Foo {
static async *foo() {
yield 'foo1'
return 'foo2'
}
};
}
const { Foo } = takeAndUseWebSnapshot(createObjects, ['Foo']);
const foo = Foo.foo()
assertEquals('foo1', (await foo.next()).value);
assertEquals('foo2', (await foo.next()).value);
assertEquals(true, (await foo.next()).done);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment