Record the generator's strictness for each emitted bytecode instruction, instead of applying the executable's final strictness to every instruction during assembly. This lets class heritage and computed element names run with strict assignment semantics inside sloppy scripts. Also create the class self-binding as a strict immutable binding, matching ClassDefinitionEvaluation, and cover strict class heritage and computed names in the runtime tests.
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
test("class properties", () => {
|
|
class A {}
|
|
expect(A.name).toBe("A");
|
|
expect(A).toHaveLength(0);
|
|
});
|
|
|
|
test("class constructor prototype property descriptor", () => {
|
|
class A {}
|
|
|
|
const descriptor = Object.getOwnPropertyDescriptor(A, "prototype");
|
|
expect(descriptor.value).toBe(A.prototype);
|
|
expect(descriptor.writable).toBeFalse();
|
|
expect(descriptor.enumerable).toBeFalse();
|
|
expect(descriptor.configurable).toBeFalse();
|
|
|
|
const constructorDescriptor = Object.getOwnPropertyDescriptor(A.prototype, "constructor");
|
|
expect(constructorDescriptor.value).toBe(A);
|
|
expect(constructorDescriptor.writable).toBeTrue();
|
|
expect(constructorDescriptor.enumerable).toBeFalse();
|
|
expect(constructorDescriptor.configurable).toBeTrue();
|
|
});
|
|
|
|
test("class heritage and computed property names are strict mode code", () => {
|
|
expect(() => {
|
|
class A {
|
|
[(Object.preventExtensions({}).prop = 1)]() {}
|
|
}
|
|
}).toThrow(TypeError);
|
|
|
|
expect(() => {
|
|
const A = class {
|
|
[(Object.preventExtensions({}).prop = 1)]() {}
|
|
};
|
|
}).toThrow(TypeError);
|
|
|
|
expect(() => {
|
|
class A {
|
|
[(Object.preventExtensions({}).prop = 1)];
|
|
}
|
|
}).toThrow(TypeError);
|
|
|
|
expect(() => {
|
|
class A extends (Object.preventExtensions({}).prop = 1) {}
|
|
}).toThrow(TypeError);
|
|
|
|
expect(() => {
|
|
const A = class extends (Object.preventExtensions({}).prop = 1) {};
|
|
}).toThrow(TypeError);
|
|
});
|