Bug 1055472 - Part 2: Make the Function constructor properly subclassable. (r=Waldo)
☠☠ backed out by 4618d76a09f0 ☠ ☠
authorEric Faust <efaustbmo@mozilla.com>
Fri, 13 Nov 2015 18:22:21 -0800
changeset 273131 0ad5599d97bbba4236801c6ad2033e8c588f2904
parent 273130 38cf9e26c83285d33cb84b04b72a8dd0b80d6aa0
child 273132 3efaea09b45f3ddb99c20a963a7340b7d01970f4
push id68184
push userefaustbmo@gmail.com
push dateWed, 18 Nov 2015 22:11:26 +0000
treeherdermozilla-inbound@0389acea3fc7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersWaldo
bugs1055472
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1055472 - Part 2: Make the Function constructor properly subclassable. (r=Waldo)
js/src/jsfun.cpp
js/src/tests/ecma_6/Class/extendBuiltinConstructors.js
--- a/js/src/jsfun.cpp
+++ b/js/src/jsfun.cpp
@@ -1836,17 +1836,28 @@ FunctionConstructor(JSContext* cx, unsig
      * and so would a call to f from another top-level's script or function.
      */
     RootedAtom anonymousAtom(cx, cx->names().anonymous);
     RootedObject proto(cx);
     if (isStarGenerator) {
         proto = GlobalObject::getOrCreateStarGeneratorFunctionPrototype(cx, global);
         if (!proto)
             return false;
+    } else {
+        RootedObject toTest(cx);
+        // If we are invoked without |new|, then just use Function.prototype
+        if (args.isConstructing())
+            toTest = &args.newTarget().toObject();
+        else
+            toTest = &args.callee();
+
+        if (!GetPrototypeFromConstructor(cx, toTest, &proto))
+            return false;
     }
+
     RootedObject globalLexical(cx, &global->lexicalScope());
     RootedFunction fun(cx, NewFunctionWithProto(cx, nullptr, 0,
                                                 JSFunction::INTERPRETED_LAMBDA, globalLexical,
                                                 anonymousAtom, proto,
                                                 AllocKind::FUNCTION, TenuredObject));
     if (!fun)
         return false;
 
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Class/extendBuiltinConstructors.js
@@ -0,0 +1,26 @@
+var test = `
+
+function testBuiltin(builtin) {
+    class inst extends builtin {
+        constructor() {
+            super();
+            this.called = true;
+        }
+    }
+
+    let instance = new inst();
+    assertEq(instance instanceof inst, true);
+    assertEq(instance instanceof builtin, true);
+    assertEq(instance.called, true);
+}
+
+
+testBuiltin(Function);
+
+`;
+
+if (classesEnabled())
+    eval(test);
+
+if (typeof reportCompare === 'function')
+    reportCompare(0,0,"OK");