Commit 484a9d31 authored by barraclough@apple.com's avatar barraclough@apple.com
Browse files

Add JSValue::isFunction

https://bugs.webkit.org/show_bug.cgi?id=81935

Reviewed by Geoff Garen.

This would be useful in the WebCore bindings code.
Also, remove asFunction, replace with jsCast<JSFunction*>.

Source/JavaScriptCore: 

* API/JSContextRef.cpp:
* debugger/Debugger.cpp:
* debugger/DebuggerCallFrame.cpp:
(JSC::DebuggerCallFrame::functionName):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::valueOfFunctionConstant):
* dfg/DFGOperations.cpp:
* interpreter/CallFrame.cpp:
(JSC::CallFrame::isInlineCallFrameSlow):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::privateExecute):
* jit/JITStubs.cpp:
(JSC::DEFINE_STUB_FUNCTION):
(JSC::jitCompileFor):
(JSC::lazyLinkFor):
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::traceFunctionPrologue):
(JSC::LLInt::LLINT_SLOW_PATH_DECL):
(JSC::LLInt::setUpCall):
* runtime/Arguments.h:
(JSC::Arguments::finishCreation):
* runtime/ArrayPrototype.cpp:
(JSC::arrayProtoFuncFilter):
(JSC::arrayProtoFuncMap):
(JSC::arrayProtoFuncEvery):
(JSC::arrayProtoFuncForEach):
(JSC::arrayProtoFuncSome):
(JSC::arrayProtoFuncReduce):
(JSC::arrayProtoFuncReduceRight):
* runtime/CommonSlowPaths.h:
(JSC::CommonSlowPaths::arityCheckFor):
* runtime/Executable.h:
(JSC::FunctionExecutable::compileFor):
(JSC::FunctionExecutable::compileOptimizedFor):
* runtime/FunctionPrototype.cpp:
(JSC::functionProtoFuncToString):
* runtime/JSArray.cpp:
(JSC::JSArray::sort):
* runtime/JSFunction.cpp:
(JSC::JSFunction::argumentsGetter):
(JSC::JSFunction::callerGetter):
(JSC::JSFunction::lengthGetter):
* runtime/JSFunction.h:
(JSC):
(JSC::asJSFunction):
(JSC::JSValue::isFunction):
* runtime/JSGlobalData.cpp:
(WTF::Recompiler::operator()):
(JSC::JSGlobalData::releaseExecutableMemory):
* runtime/JSValue.h:
* runtime/StringPrototype.cpp:
(JSC::replaceUsingRegExpSearch):

Source/WebCore: 

* bindings/js/JSInjectedScriptHostCustom.cpp:
(WebCore::JSInjectedScriptHost::functionDetails):
* bindings/js/ScriptCallStackFactory.cpp:
(WebCore::createScriptCallStack):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@111739 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 8b5e5cc6
......@@ -210,7 +210,7 @@ JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
exec->interpreter()->retrieveLastCaller(callFrame, signedLineNumber, sourceID, urlString, function);
if (function)
functionName = asFunction(function)->name(exec);
functionName = jsCast<JSFunction*>(function)->name(exec);
else {
// Caller is unknown, but if frame is empty we should still add the frame, because
// something called us, and gave us arguments.
......
2012-03-22 Gavin Barraclough <barraclough@apple.com>
Add JSValue::isFunction
https://bugs.webkit.org/show_bug.cgi?id=81935
Reviewed by Geoff Garen.
This would be useful in the WebCore bindings code.
Also, remove asFunction, replace with jsCast<JSFunction*>.
* API/JSContextRef.cpp:
* debugger/Debugger.cpp:
* debugger/DebuggerCallFrame.cpp:
(JSC::DebuggerCallFrame::functionName):
* dfg/DFGGraph.h:
(JSC::DFG::Graph::valueOfFunctionConstant):
* dfg/DFGOperations.cpp:
* interpreter/CallFrame.cpp:
(JSC::CallFrame::isInlineCallFrameSlow):
* interpreter/Interpreter.cpp:
(JSC::Interpreter::privateExecute):
* jit/JITStubs.cpp:
(JSC::DEFINE_STUB_FUNCTION):
(JSC::jitCompileFor):
(JSC::lazyLinkFor):
* llint/LLIntSlowPaths.cpp:
(JSC::LLInt::traceFunctionPrologue):
(JSC::LLInt::LLINT_SLOW_PATH_DECL):
(JSC::LLInt::setUpCall):
* runtime/Arguments.h:
(JSC::Arguments::finishCreation):
* runtime/ArrayPrototype.cpp:
(JSC::arrayProtoFuncFilter):
(JSC::arrayProtoFuncMap):
(JSC::arrayProtoFuncEvery):
(JSC::arrayProtoFuncForEach):
(JSC::arrayProtoFuncSome):
(JSC::arrayProtoFuncReduce):
(JSC::arrayProtoFuncReduceRight):
* runtime/CommonSlowPaths.h:
(JSC::CommonSlowPaths::arityCheckFor):
* runtime/Executable.h:
(JSC::FunctionExecutable::compileFor):
(JSC::FunctionExecutable::compileOptimizedFor):
* runtime/FunctionPrototype.cpp:
(JSC::functionProtoFuncToString):
* runtime/JSArray.cpp:
(JSC::JSArray::sort):
* runtime/JSFunction.cpp:
(JSC::JSFunction::argumentsGetter):
(JSC::JSFunction::callerGetter):
(JSC::JSFunction::lengthGetter):
* runtime/JSFunction.h:
(JSC):
(JSC::asJSFunction):
(JSC::JSValue::isFunction):
* runtime/JSGlobalData.cpp:
(WTF::Recompiler::operator()):
(JSC::JSGlobalData::releaseExecutableMemory):
* runtime/JSValue.h:
* runtime/StringPrototype.cpp:
(JSC::replaceUsingRegExpSearch):
2012-03-21 Filip Pizlo <fpizlo@apple.com>
 
DFG speculation on booleans should be rationalized
......@@ -67,7 +67,7 @@ inline void Recompiler::operator()(JSCell* cell)
if (!cell->inherits(&JSFunction::s_info))
return;
JSFunction* function = asFunction(cell);
JSFunction* function = jsCast<JSFunction*>(cell);
if (function->executable()->isHostFunction())
return;
......
......@@ -47,7 +47,7 @@ const UString* DebuggerCallFrame::functionName() const
JSObject* function = m_callFrame->callee();
if (!function || !function->inherits(&JSFunction::s_info))
return 0;
return &asFunction(function)->name(m_callFrame);
return &jsCast<JSFunction*>(function)->name(m_callFrame);
}
UString DebuggerCallFrame::calculatedFunctionName() const
......
......@@ -242,7 +242,7 @@ public:
{
JSCell* function = getJSFunction(valueOfJSConstant(nodeIndex));
ASSERT(function);
return asFunction(function);
return jsCast<JSFunction*>(function);
}
static const char *opName(NodeType);
......
......@@ -245,7 +245,7 @@ JSCell* DFG_OPERATION operationCreateThis(ExecState* exec, JSCell* prototype)
JSGlobalData* globalData = &exec->globalData();
NativeCallFrameTracer tracer(globalData, exec);
return createThis(exec, prototype, asFunction(exec->callee()));
return createThis(exec, prototype, jsCast<JSFunction*>(exec->callee()));
}
JSCell* DFG_OPERATION operationCreateThisInlined(ExecState* exec, JSCell* prototype, JSCell* constructor)
......@@ -835,7 +835,7 @@ inline void* linkFor(ExecState* execCallee, ReturnAddressPtr returnAddress, Code
if (!calleeAsFunctionCell)
return handleHostCall(execCallee, calleeAsValue, kind);
JSFunction* callee = asFunction(calleeAsFunctionCell);
JSFunction* callee = jsCast<JSFunction*>(calleeAsFunctionCell);
execCallee->setScopeChain(callee->scopeUnchecked());
ExecutableBase* executable = callee->executable();
......@@ -887,7 +887,7 @@ inline void* virtualFor(ExecState* execCallee, CodeSpecializationKind kind)
if (UNLIKELY(!calleeAsFunctionCell))
return handleHostCall(execCallee, calleeAsValue, kind);
JSFunction* function = asFunction(calleeAsFunctionCell);
JSFunction* function = jsCast<JSFunction*>(calleeAsFunctionCell);
execCallee->setScopeChain(function->scopeUnchecked());
ExecutableBase* executable = function->executable();
if (UNLIKELY(!executable->hasJITCodeFor(kind))) {
......
......@@ -81,7 +81,7 @@ bool CallFrame::isInlineCallFrameSlow()
JSCell* calleeAsFunctionCell = getJSFunction(callee());
if (!calleeAsFunctionCell)
return false;
JSFunction* calleeAsFunction = asFunction(calleeAsFunctionCell);
JSFunction* calleeAsFunction = jsCast<JSFunction*>(calleeAsFunctionCell);
return calleeAsFunction->executable() != codeBlock()->ownerExecutable();
}
......
......@@ -4443,7 +4443,7 @@ skip_id_custom_self:
if (isHostFunction(funcVal, globalFuncEval)) {
CallFrame* newCallFrame = CallFrame::create(callFrame->registers() + registerOffset);
newCallFrame->init(0, vPC + OPCODE_LENGTH(op_call_eval), callFrame->scopeChain(), callFrame, argCount, asFunction(funcVal));
newCallFrame->init(0, vPC + OPCODE_LENGTH(op_call_eval), callFrame->scopeChain(), callFrame, argCount, jsCast<JSFunction*>(funcVal));
JSValue result = eval(newCallFrame);
if ((exceptionValue = globalData->exception))
......@@ -4496,7 +4496,7 @@ skip_id_custom_self:
goto vm_throw;
}
callFrame->init(newCodeBlock, vPC + OPCODE_LENGTH(op_call), callDataScopeChain, previousCallFrame, argCount, asFunction(v));
callFrame->init(newCodeBlock, vPC + OPCODE_LENGTH(op_call), callDataScopeChain, previousCallFrame, argCount, jsCast<JSFunction*>(v));
codeBlock = newCodeBlock;
ASSERT(codeBlock == callFrame->codeBlock());
*topCallFrameSlot = callFrame;
......@@ -4574,7 +4574,7 @@ skip_id_custom_self:
goto vm_throw;
}
newCallFrame->init(newCodeBlock, vPC + OPCODE_LENGTH(op_call_varargs), callDataScopeChain, callFrame, argCount, asFunction(v));
newCallFrame->init(newCodeBlock, vPC + OPCODE_LENGTH(op_call_varargs), callDataScopeChain, callFrame, argCount, jsCast<JSFunction*>(v));
codeBlock = newCodeBlock;
callFrame = newCallFrame;
ASSERT(codeBlock == callFrame->codeBlock());
......@@ -4785,7 +4785,7 @@ skip_id_custom_self:
int thisRegister = vPC[1].u.operand;
int protoRegister = vPC[2].u.operand;
JSFunction* constructor = asFunction(callFrame->callee());
JSFunction* constructor = jsCast<JSFunction*>(callFrame->callee());
#if !ASSERT_DISABLED
ConstructData constructData;
ASSERT(constructor->methodTable()->getConstructData(constructor, constructData) == ConstructTypeJS);
......@@ -4895,7 +4895,7 @@ skip_id_custom_self:
goto vm_throw;
}
callFrame->init(newCodeBlock, vPC + OPCODE_LENGTH(op_construct), callDataScopeChain, previousCallFrame, argCount, asFunction(v));
callFrame->init(newCodeBlock, vPC + OPCODE_LENGTH(op_construct), callDataScopeChain, previousCallFrame, argCount, jsCast<JSFunction*>(v));
codeBlock = newCodeBlock;
*topCallFrameSlot = callFrame;
vPC = newCodeBlock->instructions().begin();
......
......@@ -1281,7 +1281,7 @@ DEFINE_STUB_FUNCTION(EncodedJSValue, op_create_this)
STUB_INIT_STACK_FRAME(stackFrame);
CallFrame* callFrame = stackFrame.callFrame;
JSFunction* constructor = asFunction(callFrame->callee());
JSFunction* constructor = jsCast<JSFunction*>(callFrame->callee());
#if !ASSERT_DISABLED
ConstructData constructData;
ASSERT(constructor->methodTable()->getConstructData(constructor, constructData) == ConstructTypeJS);
......@@ -2149,7 +2149,7 @@ DEFINE_STUB_FUNCTION(JSObject*, op_new_func)
inline void* jitCompileFor(CallFrame* callFrame, CodeSpecializationKind kind)
{
JSFunction* function = asFunction(callFrame->callee());
JSFunction* function = jsCast<JSFunction*>(callFrame->callee());
ASSERT(!function->isHostFunction());
FunctionExecutable* executable = function->jsExecutable();
ScopeChainNode* callDataScopeChain = function->scope();
......@@ -2183,7 +2183,7 @@ DEFINE_STUB_FUNCTION(void*, op_construct_jitCompile)
#if !ASSERT_DISABLED
ConstructData constructData;
ASSERT(asFunction(stackFrame.callFrame->callee())->methodTable()->getConstructData(stackFrame.callFrame->callee(), constructData) == ConstructTypeJS);
ASSERT(jsCast<JSFunction*>(stackFrame.callFrame->callee())->methodTable()->getConstructData(stackFrame.callFrame->callee(), constructData) == ConstructTypeJS);
#endif
CallFrame* callFrame = stackFrame.callFrame;
......@@ -2222,7 +2222,7 @@ DEFINE_STUB_FUNCTION(void*, op_construct_arityCheck)
inline void* lazyLinkFor(CallFrame* callFrame, CodeSpecializationKind kind)
{
JSFunction* callee = asFunction(callFrame->callee());
JSFunction* callee = jsCast<JSFunction*>(callFrame->callee());
ExecutableBase* executable = callee->executable();
MacroAssemblerCodePtr codePtr;
......
......@@ -189,7 +189,7 @@ LLINT_SLOW_PATH_DECL(trace_prologue)
static void traceFunctionPrologue(ExecState* exec, const char* comment, CodeSpecializationKind kind)
{
JSFunction* callee = asFunction(exec->callee());
JSFunction* callee = jsCast<JSFunction*>(exec->callee());
FunctionExecutable* executable = callee->jsExecutable();
CodeBlock* codeBlock = &executable->generatedBytecodeFor(kind);
dataLog("%p / %p: in %s of function %p, executable %p; numVars = %u, numParameters = %u, numCalleeRegisters = %u, caller = %p.\n",
......@@ -316,22 +316,22 @@ LLINT_SLOW_PATH_DECL(entry_osr)
LLINT_SLOW_PATH_DECL(entry_osr_function_for_call)
{
return entryOSR(exec, pc, &asFunction(exec->callee())->jsExecutable()->generatedBytecodeFor(CodeForCall), "entry_osr_function_for_call", Prologue);
return entryOSR(exec, pc, &jsCast<JSFunction*>(exec->callee())->jsExecutable()->generatedBytecodeFor(CodeForCall), "entry_osr_function_for_call", Prologue);
}
LLINT_SLOW_PATH_DECL(entry_osr_function_for_construct)
{
return entryOSR(exec, pc, &asFunction(exec->callee())->jsExecutable()->generatedBytecodeFor(CodeForConstruct), "entry_osr_function_for_construct", Prologue);
return entryOSR(exec, pc, &jsCast<JSFunction*>(exec->callee())->jsExecutable()->generatedBytecodeFor(CodeForConstruct), "entry_osr_function_for_construct", Prologue);
}
LLINT_SLOW_PATH_DECL(entry_osr_function_for_call_arityCheck)
{
return entryOSR(exec, pc, &asFunction(exec->callee())->jsExecutable()->generatedBytecodeFor(CodeForCall), "entry_osr_function_for_call_arityCheck", ArityCheck);
return entryOSR(exec, pc, &jsCast<JSFunction*>(exec->callee())->jsExecutable()->generatedBytecodeFor(CodeForCall), "entry_osr_function_for_call_arityCheck", ArityCheck);
}
LLINT_SLOW_PATH_DECL(entry_osr_function_for_construct_arityCheck)
{
return entryOSR(exec, pc, &asFunction(exec->callee())->jsExecutable()->generatedBytecodeFor(CodeForConstruct), "entry_osr_function_for_construct_arityCheck", ArityCheck);
return entryOSR(exec, pc, &jsCast<JSFunction*>(exec->callee())->jsExecutable()->generatedBytecodeFor(CodeForConstruct), "entry_osr_function_for_construct_arityCheck", ArityCheck);
}
LLINT_SLOW_PATH_DECL(loop_osr)
......@@ -452,7 +452,7 @@ LLINT_SLOW_PATH_DECL(slow_path_create_arguments)
LLINT_SLOW_PATH_DECL(slow_path_create_this)
{
LLINT_BEGIN();
JSFunction* constructor = asFunction(exec->callee());
JSFunction* constructor = jsCast<JSFunction*>(exec->callee());
#if !ASSERT_DISABLED
ConstructData constructData;
......@@ -1310,7 +1310,7 @@ inline SlowPathReturnType setUpCall(ExecState* execCallee, Instruction* pc, Code
if (!calleeAsFunctionCell)
return handleHostCall(execCallee, pc, calleeAsValue, kind);
JSFunction* callee = asFunction(calleeAsFunctionCell);
JSFunction* callee = jsCast<JSFunction*>(calleeAsFunctionCell);
ScopeChainNode* scope = callee->scopeUnchecked();
JSGlobalData& globalData = *scope->globalData;
execCallee->setScopeChain(scope);
......
......@@ -158,7 +158,7 @@ namespace JSC {
Base::finishCreation(callFrame->globalData());
ASSERT(inherits(&s_info));
JSFunction* callee = asFunction(callFrame->callee());
JSFunction* callee = jsCast<JSFunction*>(callFrame->callee());
d->numArguments = callFrame->argumentCount();
d->registers = reinterpret_cast<WriteBarrier<Unknown>*>(callFrame->registers());
d->callee.set(callFrame->globalData(), this, callee);
......
......@@ -788,7 +788,7 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncFilter(ExecState* exec)
unsigned filterIndex = 0;
unsigned k = 0;
if (callType == CallTypeJS && isJSArray(thisObj)) {
JSFunction* f = asFunction(function);
JSFunction* f = jsCast<JSFunction*>(function);
JSArray* array = asArray(thisObj);
CachedCall cachedCall(exec, f, 3);
for (; k < length && !exec->hadException(); ++k) {
......@@ -846,7 +846,7 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncMap(ExecState* exec)
JSArray* resultArray = constructEmptyArray(exec, length);
unsigned k = 0;
if (callType == CallTypeJS && isJSArray(thisObj)) {
JSFunction* f = asFunction(function);
JSFunction* f = jsCast<JSFunction*>(function);
JSArray* array = asArray(thisObj);
CachedCall cachedCall(exec, f, 3);
for (; k < length && !exec->hadException(); ++k) {
......@@ -909,7 +909,7 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncEvery(ExecState* exec)
unsigned k = 0;
if (callType == CallTypeJS && isJSArray(thisObj)) {
JSFunction* f = asFunction(function);
JSFunction* f = jsCast<JSFunction*>(function);
JSArray* array = asArray(thisObj);
CachedCall cachedCall(exec, f, 3);
for (; k < length && !exec->hadException(); ++k) {
......@@ -965,7 +965,7 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncForEach(ExecState* exec)
unsigned k = 0;
if (callType == CallTypeJS && isJSArray(thisObj)) {
JSFunction* f = asFunction(function);
JSFunction* f = jsCast<JSFunction*>(function);
JSArray* array = asArray(thisObj);
CachedCall cachedCall(exec, f, 3);
for (; k < length && !exec->hadException(); ++k) {
......@@ -1017,7 +1017,7 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncSome(ExecState* exec)
unsigned k = 0;
if (callType == CallTypeJS && isJSArray(thisObj)) {
JSFunction* f = asFunction(function);
JSFunction* f = jsCast<JSFunction*>(function);
JSArray* array = asArray(thisObj);
CachedCall cachedCall(exec, f, 3);
for (; k < length && !exec->hadException(); ++k) {
......@@ -1096,7 +1096,7 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduce(ExecState* exec)
}
if (callType == CallTypeJS && array) {
CachedCall cachedCall(exec, asFunction(function), 4);
CachedCall cachedCall(exec, jsCast<JSFunction*>(function), 4);
for (; i < length && !exec->hadException(); ++i) {
cachedCall.setThis(jsUndefined());
cachedCall.setArgument(0, rv);
......@@ -1173,7 +1173,7 @@ EncodedJSValue JSC_HOST_CALL arrayProtoFuncReduceRight(ExecState* exec)
}
if (callType == CallTypeJS && array) {
CachedCall cachedCall(exec, asFunction(function), 4);
CachedCall cachedCall(exec, jsCast<JSFunction*>(function), 4);
for (; i < length && !exec->hadException(); ++i) {
unsigned idx = length - i - 1;
cachedCall.setThis(jsUndefined());
......
......@@ -44,7 +44,7 @@ namespace CommonSlowPaths {
ALWAYS_INLINE ExecState* arityCheckFor(ExecState* exec, RegisterFile* registerFile, CodeSpecializationKind kind)
{
JSFunction* callee = asFunction(exec->callee());
JSFunction* callee = jsCast<JSFunction*>(exec->callee());
ASSERT(!callee->isHostFunction());
CodeBlock* newCodeBlock = &callee->jsExecutable()->generatedBytecodeFor(kind);
int argumentCountIncludingThis = exec->argumentCountIncludingThis();
......
......@@ -567,7 +567,7 @@ namespace JSC {
{
ASSERT(exec->callee());
ASSERT(exec->callee()->inherits(&JSFunction::s_info));
ASSERT(asFunction(exec->callee())->jsExecutable() == this);
ASSERT(jsCast<JSFunction*>(exec->callee())->jsExecutable() == this);
if (kind == CodeForCall)
return compileForCall(exec, scopeChainNode);
......@@ -579,7 +579,7 @@ namespace JSC {
{
ASSERT(exec->callee());
ASSERT(exec->callee()->inherits(&JSFunction::s_info));
ASSERT(asFunction(exec->callee())->jsExecutable() == this);
ASSERT(jsCast<JSFunction*>(exec->callee())->jsExecutable() == this);
if (kind == CodeForCall)
return compileOptimizedForCall(exec, scopeChainNode);
......
......@@ -102,7 +102,7 @@ EncodedJSValue JSC_HOST_CALL functionProtoFuncToString(ExecState* exec)
{
JSValue thisValue = exec->hostThisValue();
if (thisValue.inherits(&JSFunction::s_info)) {
JSFunction* function = asFunction(thisValue);
JSFunction* function = jsCast<JSFunction*>(thisValue);
if (function->isHostFunction())
return JSValue::encode(jsMakeNontrivialString(exec, "function ", function->name(exec), "() {\n [native code]\n}"));
FunctionExecutable* executable = function->jsExecutable();
......
......@@ -1622,7 +1622,7 @@ void JSArray::sort(ExecState* exec, JSValue compareFunction, CallType callType,
tree.abstractor().m_nodes.grow(nodeCount);
if (callType == CallTypeJS)
tree.abstractor().m_cachedCall = adoptPtr(new CachedCall(exec, asFunction(compareFunction), 2));
tree.abstractor().m_cachedCall = adoptPtr(new CachedCall(exec, jsCast<JSFunction*>(compareFunction), 2));
if (!tree.abstractor().m_nodes.begin()) {
throwOutOfMemoryError(exec);
......
......@@ -355,12 +355,25 @@ namespace JSC {
return static_cast<To>(from);
}
template<typename To>
inline To jsCast(JSValue from)
{
ASSERT(from.isCell() && from.asCell()->inherits(&WTF::RemovePointer<To>::Type::s_info));
return static_cast<To>(from.asCell());
}
template<typename To, typename From>
inline To jsDynamicCast(From* from)
{
return from->inherits(&WTF::RemovePointer<To>::Type::s_info) ? static_cast<To>(from) : 0;
}
template<typename To>
inline To jsDynamicCast(JSValue from)
{
return from.isCell() && from.asCell()->inherits(&WTF::RemovePointer<To>::Type::s_info) ? static_cast<To>(from.asCell()) : 0;
}
} // namespace JSC
#endif // JSCell_h
......@@ -173,21 +173,21 @@ CallType JSFunction::getCallData(JSCell* cell, CallData& callData)
JSValue JSFunction::argumentsGetter(ExecState* exec, JSValue slotBase, const Identifier&)
{
JSFunction* thisObj = asFunction(slotBase);
JSFunction* thisObj = jsCast<JSFunction*>(slotBase);
ASSERT(!thisObj->isHostFunction());
return exec->interpreter()->retrieveArgumentsFromVMCode(exec, thisObj);
}
JSValue JSFunction::callerGetter(ExecState* exec, JSValue slotBase, const Identifier&)
{
JSFunction* thisObj = asFunction(slotBase);
JSFunction* thisObj = jsCast<JSFunction*>(slotBase);
ASSERT(!thisObj->isHostFunction());
JSValue caller = exec->interpreter()->retrieveCallerFromVMCode(exec, thisObj);
// See ES5.1 15.3.5.4 - Function.caller may not be used to retrieve a strict caller.
if (!caller.isObject() || !asObject(caller)->inherits(&JSFunction::s_info))
return caller;
JSFunction* function = asFunction(caller);
JSFunction* function = jsCast<JSFunction*>(caller);
if (function->isHostFunction() || !function->jsExecutable()->isStrictMode())
return caller;
return throwTypeError(exec, "Function.caller used to retrieve strict caller");
......@@ -195,7 +195,7 @@ JSValue JSFunction::callerGetter(ExecState* exec, JSValue slotBase, const Identi
JSValue JSFunction::lengthGetter(ExecState*, JSValue slotBase, const Identifier&)
{
JSFunction* thisObj = asFunction(slotBase);
JSFunction* thisObj = jsCast<JSFunction*>(slotBase);
ASSERT(!thisObj->isHostFunction());
return jsNumber(thisObj->jsExecutable()->parameterCount());
}
......
......@@ -24,6 +24,7 @@
#ifndef JSFunction_h
#define JSFunction_h
#include "InternalFunction.h"
#include "JSObject.h"
namespace JSC {
......@@ -153,12 +154,9 @@ namespace JSC {
WriteBarrier<ScopeChainNode> m_scopeChain;
};
JSFunction* asFunction(JSValue);
inline JSFunction* asFunction(JSValue value)
inline bool JSValue::isFunction() const
{
ASSERT(asObject(value)->inherits(&JSFunction::s_info));
return static_cast<JSFunction*>(asObject(value));
return isCell() && (asCell()->inherits(&JSFunction::s_info) || asCell()->inherits(&InternalFunction::s_info));
}
} // namespace JSC
......
......@@ -81,7 +81,7 @@ inline void Recompiler::operator()(JSCell* cell)
{
if (!cell->inherits(&JSFunction::s_info))
return;
JSFunction* function = asFunction(cell);
JSFunction* function = jsCast<JSFunction*>(cell);
if (!function->executable() || function->executable()->isHostFunction())
return;
function->jsExecutable()->discardCode();
......@@ -478,7 +478,7 @@ void JSGlobalData::releaseExecutableMemory()
if (cell->inherits(&ScriptExecutable::s_info))
executable = static_cast<ScriptExecutable*>(*ptr);
else if (cell->inherits(&JSFunction::s_info)) {
JSFunction* function = asFunction(*ptr);
JSFunction* function = jsCast<JSFunction*>(*ptr);
if (function->isHostFunction())
continue;
executable = function->jsExecutable();
......
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