Closed Bug 1105463 Opened 11 years ago Closed 10 years ago

Implement default constructors for ClassDefinitions

Categories

(Core :: JavaScript Engine, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla44
Tracking Status
firefox44 --- fixed

People

(Reporter: efaust, Assigned: efaust)

References

Details

(Keywords: dev-doc-complete, Whiteboard: [DocArea=JS])

Attachments

(2 files)

The spec says that if |constructor| is not present as a property, we need to do some extra magic. Split that magic off here. More on this in bug 1066229.
Keywords: dev-doc-needed
Whiteboard: [DocArea=JS]
Attached patch Patch \o/Splinter Review
Assignee: nobody → efaustbmo
Status: NEW → ASSIGNED
Attachment #8658410 - Flags: review?(jorendorff)
Comment on attachment 8658410 [details] [diff] [review] Patch \o/ Review of attachment 8658410 [details] [diff] [review]: ----------------------------------------------------------------- Everything looks correct. Needs tests. Clearing review for now. ::: js/src/jsfun.cpp @@ +1074,5 @@ > MOZ_ASSERT(!fun->isExprBody()); > > + if (fun->isNative() && fun->native() == js::DefaultDerivedClassConstructor) { > + if ((!bodyOnly && !out.append("(...args) {\n ")) || > + !out.append("super(...args);\n}")) This spits out a "\n}" that should only appear if !bodyOnly. ::: js/src/vm/Interpreter.cpp @@ +5029,5 @@ > ReportUninitializedLexical(cx, name); > } > + > +bool > +js::DefaultClassConstructor(JSContext* cx, unsigned argc, Value* vp) I get that this doesn't fit anywhere, but vm/Interpreter.cpp is an especially crowded place... A new file would be best (vm/Classes.cpp or vm/DefaultConstructors.cpp). Dump it in jsobj.cpp if you are in a huge hurry.
Attachment #8658410 - Flags: review?(jorendorff)
Attached patch Tests!Splinter Review
These should all look familiar ;)
Attachment #8663135 - Flags: review?(jorendorff)
Comment on attachment 8663135 [details] [diff] [review] Tests! Review of attachment 8663135 [details] [diff] [review]: ----------------------------------------------------------------- Looks good. ::: js/src/tests/ecma_6/Class/superCallInvalidBase.js @@ +4,5 @@ > constructor() { super(); } > } > > assertThrowsInstanceOf(() => new instance(), TypeError); > +assertThrowsInstanceOf(() => new class extends null { }(), TypeError); Please add: class Foo extends Object {} Object.setPrototypeOf(Foo, Math.sin); // not a constructor assertThrowsInstanceOf(() => new Foo, TypeError); Object.setPrototypeOf(Foo, Object.create(Object)); // still not a constructor assertThrowsInstanceOf(() => new Foo, TypeError);
Attachment #8663135 - Flags: review?(jorendorff) → review+
Comment on attachment 8658410 [details] [diff] [review] Patch \o/ Review of attachment 8658410 [details] [diff] [review]: ----------------------------------------------------------------- r=me, let's go ::: js/src/vm/Interpreter.cpp @@ +5081,5 @@ > + } > + > + ConstructArgs constArgs(cx); > + if (!FillArgumentsFromArraylike(cx, constArgs, args)) > + return false; This made me think of a test: var cls = class {}; for (var i = 0; i < 1000; i++) cls = class extends cls {}; assertThrowsInstanceOf(() => new cls, InternalError); // too much recursion var manyArgs = []; manyArgs[30000] = "x"; assertThrowsInstanceOf(() => new cls(...manyArgs), InternalError); // too much recursion And, the same thing but with an explicit `constructor(...args) { super(...args); }` please. (decoder's fuzzer should have that 1000-deep class lineage in its arsenal.) (I'm not actually sure InternalError is correct, whatever happens is probably OK as long as it doesn't crash... or return normally!)
Attachment #8658410 - Flags: review+
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla44
Got it stuck, canceling ni?
Flags: needinfo?(efaustbmo)
Depends on: 1214970
Depends on: 1254122
Depends on: 1311060
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: