Commit 897fecd5 authored by verwaest's avatar verwaest Committed by Commit bot

Improve the CallSite constructor

BUG=

Review URL: https://codereview.chromium.org/1510833003

Cr-Commit-Position: refs/heads/master@{#32722}
parent ea1442d7
...@@ -566,10 +566,18 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) { ...@@ -566,10 +566,18 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) {
// Error implementation // Error implementation
function CallSite(receiver, fun, pos, strict_mode) { function CallSite(receiver, fun, pos, strict_mode) {
if (!IS_FUNCTION(fun)) {
throw MakeTypeError(kCallSiteExpectsFunction, typeof fun);
}
if (IS_UNDEFINED(new.target)) {
return new CallSite(receiver, fun, pos, strict_mode);
}
SET_PRIVATE(this, callSiteReceiverSymbol, receiver); SET_PRIVATE(this, callSiteReceiverSymbol, receiver);
SET_PRIVATE(this, callSiteFunctionSymbol, fun); SET_PRIVATE(this, callSiteFunctionSymbol, fun);
SET_PRIVATE(this, callSitePositionSymbol, pos); SET_PRIVATE(this, callSitePositionSymbol, TO_INT32(pos));
SET_PRIVATE(this, callSiteStrictSymbol, strict_mode); SET_PRIVATE(this, callSiteStrictSymbol, TO_BOOLEAN(strict_mode));
} }
function CallSiteGetThis() { function CallSiteGetThis() {
......
...@@ -163,10 +163,9 @@ CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj) ...@@ -163,10 +163,9 @@ CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj)
fun_ = Handle<JSFunction>::cast(maybe_function); fun_ = Handle<JSFunction>::cast(maybe_function);
receiver_ = JSObject::GetDataProperty( receiver_ = JSObject::GetDataProperty(
call_site_obj, isolate->factory()->call_site_receiver_symbol()); call_site_obj, isolate->factory()->call_site_receiver_symbol());
pos_ = Handle<Smi>::cast(JSObject::GetDataProperty( CHECK(JSObject::GetDataProperty(
call_site_obj, call_site_obj, isolate->factory()->call_site_position_symbol())
isolate->factory()->call_site_position_symbol())) ->ToInt32(&pos_));
->value();
} }
......
...@@ -68,7 +68,7 @@ class CallSite { ...@@ -68,7 +68,7 @@ class CallSite {
Isolate* isolate_; Isolate* isolate_;
Handle<Object> receiver_; Handle<Object> receiver_;
Handle<JSFunction> fun_; Handle<JSFunction> fun_;
int pos_; int32_t pos_;
}; };
...@@ -93,6 +93,8 @@ class CallSite { ...@@ -93,6 +93,8 @@ class CallSite {
T(CalledNonCallable, "% is not a function") \ T(CalledNonCallable, "% is not a function") \
T(CalledOnNonObject, "% called on non-object") \ T(CalledOnNonObject, "% called on non-object") \
T(CalledOnNullOrUndefined, "% called on null or undefined") \ T(CalledOnNullOrUndefined, "% called on null or undefined") \
T(CallSiteExpectsFunction, \
"CallSite expects function as second argument, got %") \
T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \ T(CannotConvertToPrimitive, "Cannot convert object to primitive value") \
T(CannotPreventExt, "Cannot prevent extensions") \ T(CannotPreventExt, "Cannot prevent extensions") \
T(CannotFreezeArrayBufferView, \ T(CannotFreezeArrayBufferView, \
......
// Copyright 2015 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.
Error.prepareStackTrace = (e,s) => s;
var constructor = Error().stack[0].constructor;
// Second argument needs to be a function.
assertThrows(()=>constructor({}, {}, 1, false), TypeError);
var receiver = {};
function f() {}
var site = constructor.call(null, receiver, f, {valueOf() { return 0 }}, false);
assertEquals(receiver, site.getThis());
assertEquals(1, site.getLineNumber());
assertEquals(1, site.getColumnNumber());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment