diff --git a/rhino/src/main/java/org/mozilla/javascript/BaseFunction.java b/rhino/src/main/java/org/mozilla/javascript/BaseFunction.java index fbaae75043..ab0c6fb76f 100644 --- a/rhino/src/main/java/org/mozilla/javascript/BaseFunction.java +++ b/rhino/src/main/java/org/mozilla/javascript/BaseFunction.java @@ -408,6 +408,11 @@ public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] ar @Override public Scriptable construct(Context cx, Scriptable scope, Object[] args) { + if (this.getHomeObject() != null) { + // Only methods have home objects associated with them + throw ScriptRuntime.typeErrorById("msg.not.ctor", getFunctionName()); + } + Scriptable result = createObject(cx, scope); if (result != null) { Object val = call(cx, scope, result, args); diff --git a/rhino/src/main/java/org/mozilla/javascript/Interpreter.java b/rhino/src/main/java/org/mozilla/javascript/Interpreter.java index d777ae172d..e1700e6a57 100644 --- a/rhino/src/main/java/org/mozilla/javascript/Interpreter.java +++ b/rhino/src/main/java/org/mozilla/javascript/Interpreter.java @@ -2206,6 +2206,13 @@ private static Object interpretLoop(Context cx, CallFrame frame, Object throwabl if (lhs instanceof InterpretedFunction) { InterpretedFunction f = (InterpretedFunction) lhs; if (frame.fnOrScript.securityDomain == f.securityDomain) { + if (f.getHomeObject() != null) { + // Only methods have home objects associated with + // them + throw ScriptRuntime.typeErrorById( + "msg.not.ctor", f.getFunctionName()); + } + Scriptable newInstance = f.createObject(cx, frame.scope); CallFrame calleeFrame = diff --git a/tests/testsrc/jstests/harmony/method-definition.js b/tests/testsrc/jstests/harmony/method-definition.js index 50c475e480..17bc5a7ccd 100644 --- a/tests/testsrc/jstests/harmony/method-definition.js +++ b/tests/testsrc/jstests/harmony/method-definition.js @@ -63,7 +63,10 @@ assertEquals(123, { }.abc()); // Method is the kind of function, that is non-constructor. -// assertThrows('new (({ a() {} }).a)', TypeError); +assertThrows(function() { + new (({ a() {} }).a) +}, TypeError); +assertNotNull(new (({ notAMethod: function() {} }).notAMethod)); var desc = Object.getOwnPropertyDescriptor({ a() { diff --git a/tests/testsrc/test262.properties b/tests/testsrc/test262.properties index 516aa6903a..af5e4e68d2 100644 --- a/tests/testsrc/test262.properties +++ b/tests/testsrc/test262.properties @@ -4857,7 +4857,7 @@ language/expressions/new 41/59 (69.49%) ~language/expressions/new.target -language/expressions/object 719/1169 (61.51%) +language/expressions/object 717/1169 (61.33%) dstr/async-gen-meth-ary-init-iter-close.js {unsupported: [async-iteration, async]} dstr/async-gen-meth-ary-init-iter-get-err.js {unsupported: [async-iteration]} dstr/async-gen-meth-ary-init-iter-get-err-array-prototype.js {unsupported: [async-iteration]} @@ -5461,7 +5461,6 @@ language/expressions/object 719/1169 (61.51%) method-definition/gen-yield-spread-arr-multiple.js method-definition/gen-yield-spread-arr-single.js method-definition/gen-yield-spread-obj.js - method-definition/generator-invoke-ctor.js method-definition/generator-invoke-fn-strict.js non-strict method-definition/generator-length-dflt.js method-definition/generator-name-prop-string.js @@ -5480,7 +5479,6 @@ language/expressions/object 719/1169 (61.51%) method-definition/meth-eval-var-scope-syntax-err.js non-strict method-definition/meth-object-destructuring-param-strict-body.js method-definition/meth-rest-param-strict-body.js - method-definition/name-invoke-ctor.js method-definition/name-invoke-fn-strict.js non-strict method-definition/name-length-dflt.js method-definition/name-name-prop-string.js