Improve the CallSite constructor

BUG=

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

Cr-Commit-Position: refs/heads/master@{#32722}
This commit is contained in:
verwaest 2015-12-09 09:28:19 -08:00 committed by Commit bot
parent ea1442d768
commit 897fecd58c
4 changed files with 33 additions and 7 deletions

View File

@ -566,10 +566,18 @@ function GetStackTraceLine(recv, fun, pos, isGlobal) {
// Error implementation
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, callSiteFunctionSymbol, fun);
SET_PRIVATE(this, callSitePositionSymbol, pos);
SET_PRIVATE(this, callSiteStrictSymbol, strict_mode);
SET_PRIVATE(this, callSitePositionSymbol, TO_INT32(pos));
SET_PRIVATE(this, callSiteStrictSymbol, TO_BOOLEAN(strict_mode));
}
function CallSiteGetThis() {

View File

@ -163,10 +163,9 @@ CallSite::CallSite(Isolate* isolate, Handle<JSObject> call_site_obj)
fun_ = Handle<JSFunction>::cast(maybe_function);
receiver_ = JSObject::GetDataProperty(
call_site_obj, isolate->factory()->call_site_receiver_symbol());
pos_ = Handle<Smi>::cast(JSObject::GetDataProperty(
call_site_obj,
isolate->factory()->call_site_position_symbol()))
->value();
CHECK(JSObject::GetDataProperty(
call_site_obj, isolate->factory()->call_site_position_symbol())
->ToInt32(&pos_));
}

View File

@ -68,7 +68,7 @@ class CallSite {
Isolate* isolate_;
Handle<Object> receiver_;
Handle<JSFunction> fun_;
int pos_;
int32_t pos_;
};
@ -93,6 +93,8 @@ class CallSite {
T(CalledNonCallable, "% is not a function") \
T(CalledOnNonObject, "% called on non-object") \
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(CannotPreventExt, "Cannot prevent extensions") \
T(CannotFreezeArrayBufferView, \

17
test/mjsunit/callsite.js Normal file
View File

@ -0,0 +1,17 @@
// 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());