[turbofan] Fix exception message for non-constructables.

This fixes the message reported via the {TypeError} thrown when trying
to call a non-constructable function as a constructor. Also adds some
more related message tests for similar exceptions.

R=bmeurer@chromium.org
TEST=message/call-non-constructable
BUG=chromium:661579

Review-Url: https://codereview.chromium.org/2523803003
Cr-Commit-Position: refs/heads/master@{#41220}
This commit is contained in:
mstarzinger 2016-11-23 05:17:13 -08:00 committed by Commit bot
parent a127fffc1b
commit 2b96c9d7c0
9 changed files with 63 additions and 1 deletions

View File

@ -412,7 +412,8 @@ Reduction JSCallReducer::ReduceJSCallConstruct(Node* node) {
if (!function->IsConstructor()) {
NodeProperties::ReplaceValueInputs(node, target);
NodeProperties::ChangeOp(
node, javascript()->CallRuntime(Runtime::kThrowCalledNonCallable));
node, javascript()->CallRuntime(
Runtime::kThrowConstructedNonConstructable));
return Changed(node);
}

View File

@ -0,0 +1,8 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Note that {unescape} is an example of a non-constructable function. If that
// ever changes and this test needs to be adapted, make sure to choose another
// non-constructable {JSFunction} object instead.
new unescape();

View File

@ -0,0 +1,9 @@
# Copyright 2016 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
*%(basename)s:8: TypeError: unescape is not a constructor
new unescape();
^
TypeError: unescape is not a constructor
at *%(basename)s:8:1

View File

@ -0,0 +1,6 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var non_callable = 0;
new non_callable();

View File

@ -0,0 +1,9 @@
# Copyright 2016 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
*%(basename)s:6: TypeError: non_callable is not a constructor
new non_callable();
^
TypeError: non_callable is not a constructor
at *%(basename)s:6:1

View File

@ -0,0 +1,6 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var non_callable = 0;
non_callable();

View File

@ -0,0 +1,9 @@
# Copyright 2016 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
*%(basename)s:6: TypeError: non_callable is not a function
non_callable();
^
TypeError: non_callable is not a function
at *%(basename)s:6:1

View File

@ -0,0 +1,5 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
not_declared();

View File

@ -0,0 +1,9 @@
# Copyright 2016 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
*%(basename)s:5: ReferenceError: not_declared is not defined
not_declared();
^
ReferenceError: not_declared is not defined
at *%(basename)s:5:1