Title: [111739] trunk/Source
Revision
111739
Author
[email protected]
Date
2012-03-22 11:54:50 -0700 (Thu, 22 Mar 2012)

Log Message

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/_javascript_Core: 

* 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):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSContextRef.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/API/JSContextRef.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/API/JSContextRef.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -210,7 +210,7 @@
         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.

Modified: trunk/Source/_javascript_Core/ChangeLog (111738 => 111739)


--- trunk/Source/_javascript_Core/ChangeLog	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-03-22 18:54:50 UTC (rev 111739)
@@ -1,3 +1,66 @@
+2012-03-22  Gavin Barraclough  <[email protected]>
+
+        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  <[email protected]>
 
         DFG speculation on booleans should be rationalized

Modified: trunk/Source/_javascript_Core/debugger/Debugger.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/debugger/Debugger.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/debugger/Debugger.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -67,7 +67,7 @@
     if (!cell->inherits(&JSFunction::s_info))
         return;
 
-    JSFunction* function = asFunction(cell);
+    JSFunction* function = jsCast<JSFunction*>(cell);
     if (function->executable()->isHostFunction())
         return;
 

Modified: trunk/Source/_javascript_Core/debugger/DebuggerCallFrame.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/debugger/DebuggerCallFrame.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/debugger/DebuggerCallFrame.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -47,7 +47,7 @@
     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

Modified: trunk/Source/_javascript_Core/dfg/DFGGraph.h (111738 => 111739)


--- trunk/Source/_javascript_Core/dfg/DFGGraph.h	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/dfg/DFGGraph.h	2012-03-22 18:54:50 UTC (rev 111739)
@@ -242,7 +242,7 @@
     {
         JSCell* function = getJSFunction(valueOfJSConstant(nodeIndex));
         ASSERT(function);
-        return asFunction(function);
+        return jsCast<JSFunction*>(function);
     }
 
     static const char *opName(NodeType);

Modified: trunk/Source/_javascript_Core/dfg/DFGOperations.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/dfg/DFGOperations.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/dfg/DFGOperations.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -245,7 +245,7 @@
     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 @@
     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 @@
     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))) {

Modified: trunk/Source/_javascript_Core/interpreter/CallFrame.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/interpreter/CallFrame.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/interpreter/CallFrame.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -81,7 +81,7 @@
     JSCell* calleeAsFunctionCell = getJSFunction(callee());
     if (!calleeAsFunctionCell)
         return false;
-    JSFunction* calleeAsFunction = asFunction(calleeAsFunctionCell);
+    JSFunction* calleeAsFunction = jsCast<JSFunction*>(calleeAsFunctionCell);
     return calleeAsFunction->executable() != codeBlock()->ownerExecutable();
 }
 

Modified: trunk/Source/_javascript_Core/interpreter/Interpreter.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/interpreter/Interpreter.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -4443,7 +4443,7 @@
 
         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 @@
                 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 @@
                 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 @@
         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 @@
                 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();

Modified: trunk/Source/_javascript_Core/jit/JITStubs.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/jit/JITStubs.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/jit/JITStubs.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -1281,7 +1281,7 @@
     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 @@
 
 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 @@
 
 #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 @@
 
 inline void* lazyLinkFor(CallFrame* callFrame, CodeSpecializationKind kind)
 {
-    JSFunction* callee = asFunction(callFrame->callee());
+    JSFunction* callee = jsCast<JSFunction*>(callFrame->callee());
     ExecutableBase* executable = callee->executable();
 
     MacroAssemblerCodePtr codePtr;

Modified: trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/llint/LLIntSlowPaths.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -189,7 +189,7 @@
 
 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_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_this)
 {
     LLINT_BEGIN();
-    JSFunction* constructor = asFunction(exec->callee());
+    JSFunction* constructor = jsCast<JSFunction*>(exec->callee());
     
 #if !ASSERT_DISABLED
     ConstructData constructData;
@@ -1310,7 +1310,7 @@
     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);

Modified: trunk/Source/_javascript_Core/runtime/Arguments.h (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/Arguments.h	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/Arguments.h	2012-03-22 18:54:50 UTC (rev 111739)
@@ -158,7 +158,7 @@
         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);

Modified: trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -788,7 +788,7 @@
     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 @@
     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 @@
 
     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 @@
 
     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 @@
 
     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 @@
     }
 
     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 @@
     }
     
     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());

Modified: trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/CommonSlowPaths.h	2012-03-22 18:54:50 UTC (rev 111739)
@@ -44,7 +44,7 @@
 
 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();

Modified: trunk/Source/_javascript_Core/runtime/Executable.h (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/Executable.h	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/Executable.h	2012-03-22 18:54:50 UTC (rev 111739)
@@ -567,7 +567,7 @@
         {
             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 @@
         {
             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);

Modified: trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/FunctionPrototype.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -102,7 +102,7 @@
 {
     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();

Modified: trunk/Source/_javascript_Core/runtime/JSArray.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/JSArray.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/JSArray.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -1622,7 +1622,7 @@
     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);

Modified: trunk/Source/_javascript_Core/runtime/JSCell.h (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/JSCell.h	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/JSCell.h	2012-03-22 18:54:50 UTC (rev 111739)
@@ -355,12 +355,25 @@
         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

Modified: trunk/Source/_javascript_Core/runtime/JSFunction.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/JSFunction.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/JSFunction.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -173,21 +173,21 @@
 
 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::lengthGetter(ExecState*, JSValue slotBase, const Identifier&)
 {
-    JSFunction* thisObj = asFunction(slotBase);
+    JSFunction* thisObj = jsCast<JSFunction*>(slotBase);
     ASSERT(!thisObj->isHostFunction());
     return jsNumber(thisObj->jsExecutable()->parameterCount());
 }

Modified: trunk/Source/_javascript_Core/runtime/JSFunction.h (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/JSFunction.h	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/JSFunction.h	2012-03-22 18:54:50 UTC (rev 111739)
@@ -24,6 +24,7 @@
 #ifndef JSFunction_h
 #define JSFunction_h
 
+#include "InternalFunction.h"
 #include "JSObject.h"
 
 namespace JSC {
@@ -153,12 +154,9 @@
         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

Modified: trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalData.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -81,7 +81,7 @@
 {
     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 @@
             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();

Modified: trunk/Source/_javascript_Core/runtime/JSValue.h (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/JSValue.h	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/JSValue.h	2012-03-22 18:54:50 UTC (rev 111739)
@@ -173,6 +173,7 @@
 
         // Querying the type.
         bool isEmpty() const;
+        bool isFunction() const;
         bool isUndefined() const;
         bool isNull() const;
         bool isUndefinedOrNull() const;

Modified: trunk/Source/_javascript_Core/runtime/StringPrototype.cpp (111738 => 111739)


--- trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/_javascript_Core/runtime/StringPrototype.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -479,7 +479,7 @@
     if (global && callType == CallTypeJS) {
         // regExp->numSubpatterns() + 1 for pattern args, + 2 for match start and string
         int argCount = regExp->numSubpatterns() + 1 + 2;
-        JSFunction* func = asFunction(replaceValue);
+        JSFunction* func = jsCast<JSFunction*>(replaceValue);
         CachedCall cachedCall(exec, func, argCount);
         if (exec->hadException())
             return JSValue::encode(jsNull());

Modified: trunk/Source/WebCore/ChangeLog (111738 => 111739)


--- trunk/Source/WebCore/ChangeLog	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/WebCore/ChangeLog	2012-03-22 18:54:50 UTC (rev 111739)
@@ -1,3 +1,18 @@
+2012-03-22  Gavin Barraclough  <[email protected]>
+
+        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*>.
+
+        * bindings/js/JSInjectedScriptHostCustom.cpp:
+        (WebCore::JSInjectedScriptHost::functionDetails):
+        * bindings/js/ScriptCallStackFactory.cpp:
+        (WebCore::createScriptCallStack):
+
 2012-03-22  Jocelyn Turcotte  <[email protected]>
 
         TiledBackingStore: Fix test regressions that appeared with r111560.

Modified: trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp (111738 => 111739)


--- trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/WebCore/bindings/js/JSInjectedScriptHostCustom.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -162,7 +162,7 @@
     JSValue value = exec->argument(0);
     if (!value.asCell()->inherits(&JSFunction::s_info))
         return jsUndefined();
-    JSFunction* function = asFunction(value);
+    JSFunction* function = jsCast<JSFunction*>(value);
 
     const SourceCode* sourceCode = function->sourceCode();
     if (!sourceCode)

Modified: trunk/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp (111738 => 111739)


--- trunk/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp	2012-03-22 18:53:45 UTC (rev 111738)
+++ trunk/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp	2012-03-22 18:54:50 UTC (rev 111739)
@@ -70,7 +70,7 @@
         exec->interpreter()->retrieveLastCaller(callFrame, signedLineNumber, sourceID, urlString, function);
         UString functionName;
         if (function)
-            functionName = asFunction(function)->name(exec);
+            functionName = jsCast<JSFunction*>(function)->name(exec);
         else {
             // Caller is unknown, but if frames is empty we should still add the frame, because
             // something called us, and gave us arguments.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to