Title: [183759] trunk
- Revision
- 183759
- Author
- [email protected]
- Date
- 2015-05-04 12:23:24 -0700 (Mon, 04 May 2015)
Log Message
Extending undefined in class syntax should throw a TypeError
https://bugs.webkit.org/show_bug.cgi?id=144284
Reviewed by Darin Adler.
Source/_javascript_Core:
The bug was caused by op_eq_null evaluating to true when compared to undefined.
Explicitly check op_eq_undefined first to detect the case where we're extending undefined.
We also had bogus test cases checked in class-syntax-extends.html. This patch also fixes them.
* bytecompiler/NodesCodegen.cpp:
(JSC::ClassExprNode::emitBytecode):
LayoutTests:
Fixed the expectation for extending undefined and removed irrelevant test cases for extending undefined
since we'll never get to instantiate these classes now.
* js/class-syntax-extends-expected.txt:
* js/script-tests/class-syntax-extends.js:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (183758 => 183759)
--- trunk/LayoutTests/ChangeLog 2015-05-04 19:22:38 UTC (rev 183758)
+++ trunk/LayoutTests/ChangeLog 2015-05-04 19:23:24 UTC (rev 183759)
@@ -1,5 +1,18 @@
2015-05-04 Ryosuke Niwa <[email protected]>
+ Extending undefined in class syntax should throw a TypeError
+ https://bugs.webkit.org/show_bug.cgi?id=144284
+
+ Reviewed by Darin Adler.
+
+ Fixed the expectation for extending undefined and removed irrelevant test cases for extending undefined
+ since we'll never get to instantiate these classes now.
+
+ * js/class-syntax-extends-expected.txt:
+ * js/script-tests/class-syntax-extends.js:
+
+2015-05-04 Ryosuke Niwa <[email protected]>
+
ES6 classes: Invalid test for constructor property
https://bugs.webkit.org/show_bug.cgi?id=144278
Modified: trunk/LayoutTests/js/class-syntax-extends-expected.txt (183758 => 183759)
--- trunk/LayoutTests/js/class-syntax-extends-expected.txt 2015-05-04 19:22:38 UTC (rev 183758)
+++ trunk/LayoutTests/js/class-syntax-extends-expected.txt 2015-05-04 19:23:24 UTC (rev 183759)
@@ -54,10 +54,8 @@
PASS x = 1; namespace = {}; namespace.A = class { constructor() { } }; try { namespace.B = class extends (namespace.A, x++) { constructor() { } } } catch (e) { } x is 2
PASS Object.getPrototypeOf((class { constructor () { } }).prototype) is Object.prototype
PASS Object.getPrototypeOf((class extends null { constructor () { super(); } }).prototype) is null
-PASS new (class extends undefined { constructor () { this } }) threw exception ReferenceError: Cannot access uninitialized variable..
-PASS new (class extends undefined { constructor () { super(); } }) threw exception TypeError: undefined is not an object (evaluating 'super()').
-PASS x = {}; new (class extends undefined { constructor () { return x; } }) is x
-PASS y = 12; new (class extends undefined { constructor () { return y; } }) threw exception TypeError: Cannot return a non-object type in the constructor of a derived class..
+PASS new (class extends undefined { constructor () { this } }) threw exception TypeError: The superclass is not an object..
+PASS x = undefined; new (class extends x { constructor () { super(); } }) threw exception TypeError: The superclass is not an object..
PASS class x {}; new (class extends null { constructor () { return new x; } }) instanceof x is true
PASS new (class extends null { constructor () { this; } }) threw exception ReferenceError: Cannot access uninitialized variable..
PASS new (class extends null { constructor () { super(); } }) threw exception TypeError: undefined is not an object (evaluating 'super()').
Modified: trunk/LayoutTests/js/script-tests/class-syntax-extends.js (183758 => 183759)
--- trunk/LayoutTests/js/script-tests/class-syntax-extends.js 2015-05-04 19:22:38 UTC (rev 183758)
+++ trunk/LayoutTests/js/script-tests/class-syntax-extends.js 2015-05-04 19:23:24 UTC (rev 183759)
@@ -70,10 +70,8 @@
shouldBe('Object.getPrototypeOf((class { constructor () { } }).prototype)', 'Object.prototype');
shouldBe('Object.getPrototypeOf((class extends null { constructor () { super(); } }).prototype)', 'null');
-shouldThrow('new (class extends undefined { constructor () { this } })', '"ReferenceError: Cannot access uninitialized variable."');
-shouldThrow('new (class extends undefined { constructor () { super(); } })', '"TypeError: undefined is not an object (evaluating \'super()\')"');
-shouldBe('x = {}; new (class extends undefined { constructor () { return x; } })', 'x');
-shouldThrow('y = 12; new (class extends undefined { constructor () { return y; } })', '"TypeError: Cannot return a non-object type in the constructor of a derived class."');
+shouldThrow('new (class extends undefined { constructor () { this } })', '"TypeError: The superclass is not an object."');
+shouldThrow('x = undefined; new (class extends x { constructor () { super(); } })', '"TypeError: The superclass is not an object."');
shouldBeTrue ('class x {}; new (class extends null { constructor () { return new x; } }) instanceof x');
shouldThrow('new (class extends null { constructor () { this; } })', '"ReferenceError: Cannot access uninitialized variable."');
shouldThrow('new (class extends null { constructor () { super(); } })', '"TypeError: undefined is not an object (evaluating \'super()\')"');
Modified: trunk/Source/_javascript_Core/ChangeLog (183758 => 183759)
--- trunk/Source/_javascript_Core/ChangeLog 2015-05-04 19:22:38 UTC (rev 183758)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-05-04 19:23:24 UTC (rev 183759)
@@ -1,5 +1,20 @@
2015-05-04 Ryosuke Niwa <[email protected]>
+ Extending undefined in class syntax should throw a TypeError
+ https://bugs.webkit.org/show_bug.cgi?id=144284
+
+ Reviewed by Darin Adler.
+
+ The bug was caused by op_eq_null evaluating to true when compared to undefined.
+ Explicitly check op_eq_undefined first to detect the case where we're extending undefined.
+
+ We also had bogus test cases checked in class-syntax-extends.html. This patch also fixes them.
+
+ * bytecompiler/NodesCodegen.cpp:
+ (JSC::ClassExprNode::emitBytecode):
+
+2015-05-04 Ryosuke Niwa <[email protected]>
+
new super should be a syntax error
https://bugs.webkit.org/show_bug.cgi?id=144282
Modified: trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp (183758 => 183759)
--- trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2015-05-04 19:22:38 UTC (rev 183758)
+++ trunk/Source/_javascript_Core/bytecompiler/NodesCodegen.cpp 2015-05-04 19:23:24 UTC (rev 183759)
@@ -2937,12 +2937,17 @@
generator.emitLoad(protoParent.get(), jsNull());
RefPtr<RegisterID> tempRegister = generator.newTemporary();
+
+ // FIXME: Throw TypeError if it's a generator function.
+ RefPtr<Label> superclassIsUndefinedLabel = generator.newLabel();
+ generator.emitJumpIfTrue(generator.emitIsUndefined(tempRegister.get(), superclass.get()), superclassIsUndefinedLabel.get());
+
RefPtr<Label> superclassIsNullLabel = generator.newLabel();
generator.emitJumpIfTrue(generator.emitUnaryOp(op_eq_null, tempRegister.get(), superclass.get()), superclassIsNullLabel.get());
- // FIXME: Throw TypeError if it's a generator function.
RefPtr<Label> superclassIsObjectLabel = generator.newLabel();
generator.emitJumpIfTrue(generator.emitIsObject(tempRegister.get(), superclass.get()), superclassIsObjectLabel.get());
+ generator.emitLabel(superclassIsUndefinedLabel.get());
generator.emitThrowTypeError(ASCIILiteral("The superclass is not an object."));
generator.emitLabel(superclassIsObjectLabel.get());
generator.emitGetById(protoParent.get(), superclass.get(), generator.propertyNames().prototype);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes