Bug 142882

Summary: Extending null should set __proto__ to null
Product: WebKit Reporter: Ryosuke Niwa <rniwa>
Component: JavaScriptCoreAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, buildbot, fpizlo, ggaren, joepeck, mhahnenb, oliver, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 140491    
Attachments:
Description Flags
Fixes the bug
none
Archive of layout-test-results from ews105 for mac-mavericks-wk2
none
Archive of layout-test-results from ews100 for mac-mavericks
none
Fixes the bug ggaren: review+

Description Ryosuke Niwa 2015-03-19 15:41:00 PDT
new (class A extends null {}).__proto__ should evalute to null according to the spec.
Function.prototype.isPrototypeOf(A) should still be true.
Comment 1 Ryosuke Niwa 2015-03-20 14:30:00 PDT
@@ -2899,6 +2903,9 @@ RegisterID* ClassExprNode::emitBytecode(BytecodeGenerator& generator, RegisterID
     prototype = generator.emitGetById(generator.newTemporary(), constructor.get(), generator.propertyNames().prototype);
 
     if (superclass) {
+        RefPtr<RegisterID> protoParent = generator.newTemporary();
+        generator.emitLoad(protoParent.get(), jsNull());
+
         RefPtr<RegisterID> tempRegister = generator.newTemporary();
         RefPtr<Label> superclassIsNullLabel = generator.newLabel();
         generator.emitJumpIfTrue(generator.emitUnaryOp(op_eq_null, tempRegister.get(), superclass.get()), superclassIsNullLabel.get());
@@ -2908,8 +2915,6 @@ RegisterID* ClassExprNode::emitBytecode(BytecodeGenerator& generator, RegisterID
         generator.emitJumpIfTrue(generator.emitIsObject(tempRegister.get(), superclass.get()), superclassIsObjectLabel.get());
         generator.emitThrowTypeError(ASCIILiteral("The superclass is not an object."));
         generator.emitLabel(superclassIsObjectLabel.get());
-
-        RefPtr<RegisterID> protoParent = generator.newTemporary();
         generator.emitGetById(protoParent.get(), superclass.get(), generator.propertyNames().prototype);
 
         RefPtr<Label> protoParentIsObjectOrNullLabel = generator.newLabel();
@@ -2918,9 +2923,9 @@ RegisterID* ClassExprNode::emitBytecode(BytecodeGenerator& generator, RegisterID
         generator.emitLabel(protoParentIsObjectOrNullLabel.get());
 
         generator.emitDirectPutById(constructor.get(), generator.propertyNames().underscoreProto, superclass.get(), PropertyNode::Unknown);
+        generator.emitLabel(superclassIsNullLabel.get());
         generator.emitDirectPutById(prototype.get(), generator.propertyNames().underscoreProto, protoParent.get(), PropertyNode::Unknown);
 
-        generator.emitLabel(superclassIsNullLabel.get());
         emitPutHomeObject(generator, constructor.get(), prototype.get());
     }
Comment 2 Ryosuke Niwa 2015-03-27 23:00:28 PDT
Created attachment 249644 [details]
Fixes the bug
Comment 3 Build Bot 2015-03-27 23:36:24 PDT
Comment on attachment 249644 [details]
Fixes the bug

Attachment 249644 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/5684121242173440

New failing tests:
js/class-syntax-super.html
js/class-syntax-call.html
Comment 4 Build Bot 2015-03-27 23:36:28 PDT
Created attachment 249645 [details]
Archive of layout-test-results from ews105 for mac-mavericks-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews105  Port: mac-mavericks-wk2  Platform: Mac OS X 10.9.5
Comment 5 Build Bot 2015-03-27 23:47:49 PDT
Comment on attachment 249644 [details]
Fixes the bug

Attachment 249644 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/5383994296238080

New failing tests:
js/class-syntax-super.html
js/class-syntax-call.html
Comment 6 Build Bot 2015-03-27 23:47:53 PDT
Created attachment 249647 [details]
Archive of layout-test-results from ews100 for mac-mavericks

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews100  Port: mac-mavericks  Platform: Mac OS X 10.9.5
Comment 7 Ryosuke Niwa 2015-03-28 01:32:11 PDT
Created attachment 249656 [details]
Fixes the bug
Comment 8 Geoffrey Garen 2015-03-30 15:51:03 PDT
Comment on attachment 249656 [details]
Fixes the bug

r=me
Comment 9 Benjamin Poulain 2015-03-30 15:57:29 PDT
View in context: https://bugs.webkit.org/attachment.cgi?id=249656&action=review

> LayoutTests/js/script-tests/class-syntax-extends.js:72
> +shouldBe('Object.getPrototypeOf((class extends null { constructor () { super(); } }).prototype)', 'null');

You should also have coverage for extending undefined.

> LayoutTests/js/script-tests/class-syntax-extends.js:74
> +shouldThrow('new (class extends null { constructor () { super(); } })', '"TypeError: undefined is not an object (evaluating \'super()\')"');

+ add a test case where the constructor return a new, completely different, object.
Comment 10 Ryosuke Niwa 2015-03-30 19:00:15 PDT
Committed r182171: <http://trac.webkit.org/changeset/182171>