Adds a JavaScriptCallFrame object and JavaScript binding with an IDL.
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 May 2008 22:27:57 +0000 (22:27 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 May 2008 22:27:57 +0000 (22:27 +0000)
This object will expose the stack to the Inspector's debugger.

Reviewed by Adam Roben.

* DerivedSources.make: Add JavaScriptCallFrame.
* bindings/js/JSJavaScriptCallFrameCustom.cpp: Added.
(WebCore::JSJavaScriptCallFrame::evaluate): Calls impl evaluate and returns the result.
(WebCore::JSJavaScriptCallFrame::scopeChain): Makes an array of the ScopeChain.
* page/JavaScriptCallFrame.cpp: Added.
(WebCore::JavaScriptCallFrame::JavaScriptCallFrame):
(WebCore::JavaScriptCallFrame::caller): Returns m_caller.
(WebCore::JavaScriptCallFrame::functionName): Returns the function
name from the ExecState if this is not global code or anonymous.
(WebCore::JavaScriptCallFrame::evaluate): Evaluates a script string
in the scope of the call frame.
* page/JavaScriptCallFrame.h: Added.
(WebCore::JavaScriptCallFrame::create): Call the ctor can return in a PassRefPtr.
(WebCore::JavaScriptCallFrame::invalidate): Sets m_mexec to 0. This prevents a
stale ExecState from being accessed after the lifetime of the ExecState.
(WebCore::JavaScriptCallFrame::isValid): Checks if m_exec is 0.
(WebCore::JavaScriptCallFrame::execState): Returns m_exec.
(WebCore::JavaScriptCallFrame::sourceIdentifier): Returns m_sourceID.
(WebCore::JavaScriptCallFrame::line): Returns m_line.
(WebCore::JavaScriptCallFrame::setLine): Sets m_line.
(WebCore::JavaScriptCallFrame::scopeChain): Returns by reference m_exec->scopeChain().
* page/JavaScriptCallFrame.idl: Added.
* WebCore.xcodeproj/project.pbxproj: Add new files.
* WebCore.vcproj/WebCore.vcproj: Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@33397 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/DerivedSources.make
WebCore/WebCore.vcproj/WebCore.vcproj
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp [new file with mode: 0644]
WebCore/page/JavaScriptCallFrame.cpp [new file with mode: 0644]
WebCore/page/JavaScriptCallFrame.h [new file with mode: 0644]
WebCore/page/JavaScriptCallFrame.idl [new file with mode: 0644]

index 5230adf..4329863 100644 (file)
@@ -1,5 +1,37 @@
 2008-05-13  Timothy Hatcher  <timothy@apple.com>
 
+        Adds a JavaScriptCallFrame object and JavaScript binding with an IDL.
+        This object will expose the stack to the Inspector's debugger.
+
+        Reviewed by Adam Roben.
+
+        * DerivedSources.make: Add JavaScriptCallFrame.
+        * bindings/js/JSJavaScriptCallFrameCustom.cpp: Added.
+        (WebCore::JSJavaScriptCallFrame::evaluate): Calls impl evaluate and returns the result.
+        (WebCore::JSJavaScriptCallFrame::scopeChain): Makes an array of the ScopeChain.
+        * page/JavaScriptCallFrame.cpp: Added.
+        (WebCore::JavaScriptCallFrame::JavaScriptCallFrame):
+        (WebCore::JavaScriptCallFrame::caller): Returns m_caller.
+        (WebCore::JavaScriptCallFrame::functionName): Returns the function
+        name from the ExecState if this is not global code or anonymous.
+        (WebCore::JavaScriptCallFrame::evaluate): Evaluates a script string
+        in the scope of the call frame.
+        * page/JavaScriptCallFrame.h: Added.
+        (WebCore::JavaScriptCallFrame::create): Call the ctor can return in a PassRefPtr.
+        (WebCore::JavaScriptCallFrame::invalidate): Sets m_mexec to 0. This prevents a
+        stale ExecState from being accessed after the lifetime of the ExecState.
+        (WebCore::JavaScriptCallFrame::isValid): Checks if m_exec is 0.
+        (WebCore::JavaScriptCallFrame::execState): Returns m_exec.
+        (WebCore::JavaScriptCallFrame::sourceIdentifier): Returns m_sourceID.
+        (WebCore::JavaScriptCallFrame::line): Returns m_line.
+        (WebCore::JavaScriptCallFrame::setLine): Sets m_line.
+        (WebCore::JavaScriptCallFrame::scopeChain): Returns by reference m_exec->scopeChain().
+        * page/JavaScriptCallFrame.idl: Added.
+        * WebCore.xcodeproj/project.pbxproj: Add new files.
+        * WebCore.vcproj/WebCore.vcproj: Ditto.
+
+2008-05-13  Timothy Hatcher  <timothy@apple.com>
+
         Add a new WebInspector.Object base class that will be used for
         a few objects in the Web Inspector to support listeners on any
         object. This will help add more abstraction to the Inspector.
index 6f4ab5f..68f589d 100644 (file)
@@ -359,6 +359,8 @@ all : \
     JSEventTargetBase.lut.h \
     JSRGBColor.lut.h \
     \
+    JSJavaScriptCallFrame.h \
+    \
     JSHTMLInputElementBaseTable.cpp \
     \
     CSSGrammar.cpp \
index 3a6955f..f4c6251 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSJavaScriptCallFrame.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSJavaScriptCallFrame.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="$(WebKitOutputDir)\obj\$(ProjectName)\DerivedSources\JSKeyboardEvent.cpp"\r
                                >\r
                        </File>\r
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath="..\page\JavaScriptCallFrame.cpp"\r
+                               >\r
+                               <FileConfiguration\r
+                                       Name="Release_PGO|Win32"\r
+                                       >\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               WholeProgramOptimization="true"\r
+                                       />\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\page\JavaScriptCallFrame.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath="..\page\JavaScriptDebugListener.h"\r
                                >\r
                        </File>\r
                                        >\r
                                </File>\r
                                <File\r
+                                       RelativePath="..\bindings\js\JSJavaScriptCallFrameCustom.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
                                        RelativePath="..\bindings\js\JSLocationCustom.cpp"\r
                                        >\r
                                </File>\r
index ec94eaa..d6bc031 100644 (file)
                1C26497C0D7E24EC00BD10F2 /* PageMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C26497B0D7E24EC00BD10F2 /* PageMac.cpp */; };
                1C4C8F020AD85D87009475CE /* DeleteButtonController.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C4C8F000AD85D87009475CE /* DeleteButtonController.h */; };
                1C4C8F660AD8655D009475CE /* DeleteButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C4C8F640AD8655D009475CE /* DeleteButton.h */; };
+               1C5FAED10DCFD90100D58F78 /* JSJavaScriptCallFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C5FAECF0DCFD90100D58F78 /* JSJavaScriptCallFrame.cpp */; };
+               1C5FAED20DCFD90100D58F78 /* JSJavaScriptCallFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C5FAED00DCFD90100D58F78 /* JSJavaScriptCallFrame.h */; };
+               1C5FAEE70DCFDA6800D58F78 /* JSJavaScriptCallFrameCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C5FAEE60DCFDA6800D58F78 /* JSJavaScriptCallFrameCustom.cpp */; };
+               1CA19CAE0DC1145F0065A994 /* JavaScriptCallFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CA19CAC0DC1145F0065A994 /* JavaScriptCallFrame.h */; };
+               1CA19CAF0DC1145F0065A994 /* JavaScriptCallFrame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CA19CAD0DC1145F0065A994 /* JavaScriptCallFrame.cpp */; };
                1CAF34810A6C405200ABE06E /* WebScriptObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CAF347E0A6C405200ABE06E /* WebScriptObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1CAF34820A6C405200ABE06E /* WebScriptObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1CAF347F0A6C405200ABE06E /* WebScriptObject.mm */; };
                1CAF34830A6C405200ABE06E /* WebScriptObjectPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1CAF34800A6C405200ABE06E /* WebScriptObjectPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1C4C8F000AD85D87009475CE /* DeleteButtonController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeleteButtonController.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                1C4C8F630AD8655D009475CE /* DeleteButton.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeleteButton.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
                1C4C8F640AD8655D009475CE /* DeleteButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeleteButton.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
+               1C5FAE510DCFC7A300D58F78 /* JavaScriptCallFrame.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = JavaScriptCallFrame.idl; sourceTree = "<group>"; };
+               1C5FAECF0DCFD90100D58F78 /* JSJavaScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSJavaScriptCallFrame.cpp; sourceTree = "<group>"; };
+               1C5FAED00DCFD90100D58F78 /* JSJavaScriptCallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSJavaScriptCallFrame.h; sourceTree = "<group>"; };
+               1C5FAEE60DCFDA6800D58F78 /* JSJavaScriptCallFrameCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSJavaScriptCallFrameCustom.cpp; sourceTree = "<group>"; };
                1C904DF90BA9D2C80081E9D0 /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; };
+               1CA19CAC0DC1145F0065A994 /* JavaScriptCallFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptCallFrame.h; sourceTree = "<group>"; };
+               1CA19CAD0DC1145F0065A994 /* JavaScriptCallFrame.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JavaScriptCallFrame.cpp; sourceTree = "<group>"; };
                1CAF347E0A6C405200ABE06E /* WebScriptObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObject.h; sourceTree = "<group>"; };
                1CAF347F0A6C405200ABE06E /* WebScriptObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebScriptObject.mm; sourceTree = "<group>"; };
                1CAF34800A6C405200ABE06E /* WebScriptObjectPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObjectPrivate.h; sourceTree = "<group>"; };
                                A83B790E0CCAFF97000B0825 /* CSS */,
                                A83B79120CCB003F000B0825 /* Events */,
                                A83B79080CCAFF2B000B0825 /* HTML */,
+                               1C5FAECA0DCFD8C900D58F78 /* Inspector */,
                                1AC226020DB69EA70089B669 /* Offline */,
                                BC9854460CD3DA5F00069BC1 /* Ranges */,
                                A83B79150CCB0078000B0825 /* Storage */,
                        tabWidth = 8;
                        usesTabs = 0;
                };
+               1C5FAECA0DCFD8C900D58F78 /* Inspector */ = {
+                       isa = PBXGroup;
+                       children = (
+                               1C5FAECF0DCFD90100D58F78 /* JSJavaScriptCallFrame.cpp */,
+                               1C5FAED00DCFD90100D58F78 /* JSJavaScriptCallFrame.h */,
+                       );
+                       name = Inspector;
+                       sourceTree = "<group>";
+               };
                1CDD44660BA9C80000F90147 /* Configurations */ = {
                        isa = PBXGroup;
                        children = (
                                06693DB70BFBA2F400216072 /* InspectorClient.h */,
                                06693DB80BFBA2F400216072 /* InspectorController.cpp */,
                                06693DB90BFBA2F400216072 /* InspectorController.h */,
+                               1CA19CAD0DC1145F0065A994 /* JavaScriptCallFrame.cpp */,
+                               1CA19CAC0DC1145F0065A994 /* JavaScriptCallFrame.h */,
+                               1C5FAE510DCFC7A300D58F78 /* JavaScriptCallFrame.idl */,
                                C02B14BF0D81E02A00D8A970 /* JavaScriptDebugListener.h */,
                                C02B14C00D81E02A00D8A970 /* JavaScriptDebugServer.cpp */,
                                C02B14C10D81E02A00D8A970 /* JavaScriptDebugServer.h */,
                                448AD27A0A4813790023D179 /* JSHTMLOptionsCollectionCustom.cpp */,
                                BC17F9650B64EBB8004A65CB /* JSHTMLSelectElementCustom.cpp */,
                                AB4CB4EA0B8BDA3D009F40B0 /* JSHTMLSelectElementCustom.h */,
+                               1C5FAEE60DCFDA6800D58F78 /* JSJavaScriptCallFrameCustom.cpp */,
                                BCE1C43F0D9830F4003B02F2 /* JSLocationCustom.cpp */,
                                A9C6E6460D7465CA006442E9 /* JSMimeTypeArrayCustom.cpp */,
                                BCD9C25F0C17AA67005C90A2 /* JSNamedNodeMapCustom.cpp */,
                                F916C48E0DB510F80076CD83 /* JSXMLHttpRequestProgressEvent.h in Headers */,
                                BCD0FC4F0DBD720B00B2F630 /* DOMRGBColorInternal.h in Headers */,
                                BC99812E0DBE807A008CE9EF /* DOMAbstractViewFrame.h in Headers */,
+                               1CA19CAE0DC1145F0065A994 /* JavaScriptCallFrame.h in Headers */,
                                511F23180DC160DA004F0032 /* LocalStorageTask.h in Headers */,
                                511F231A0DC160DA004F0032 /* LocalStorageThread.h in Headers */,
                                BC5A12E00DC0414800C9AFAD /* CSSReflectValue.h in Headers */,
                                BCEFE1EB0DCA5F6400739219 /* JSXSLTProcessor.h in Headers */,
                                BCE99EC40DCA624100182683 /* JSXSLTProcessorConstructor.h in Headers */,
                                BCBFB53D0DCD29CF0019B3E5 /* JSDOMWindowShell.h in Headers */,
+                               1C5FAED20DCFD90100D58F78 /* JSJavaScriptCallFrame.h in Headers */,
                                2999869E0DD0DEEA00F8D261 /* AccessibilityListBoxOption.h in Headers */,
                                299986A00DD0DEEA00F8D261 /* AccessibilityListBox.h in Headers */,
                                BC34C33B0DD607DE00090123 /* AccessControlList.h in Headers */,
                                F9F0ED790DB50CA200D16DB9 /* XMLHttpRequestProgressEvent.cpp in Sources */,
                                F916C48D0DB510F80076CD83 /* JSXMLHttpRequestProgressEvent.cpp in Sources */,
                                BCD0FBD00DBD625E00B2F630 /* DOMAbstractView.mm in Sources */,
+                               1CA19CAF0DC1145F0065A994 /* JavaScriptCallFrame.cpp in Sources */,
                                511F23170DC160DA004F0032 /* LocalStorageTask.cpp in Sources */,
                                511F23190DC160DA004F0032 /* LocalStorageThread.cpp in Sources */,
                                BC5A12DF0DC0414800C9AFAD /* CSSReflectValue.cpp in Sources */,
                                BCEFE1EA0DCA5F6400739219 /* JSXSLTProcessor.cpp in Sources */,
                                BCE99EC30DCA624100182683 /* JSXSLTProcessorConstructor.cpp in Sources */,
                                BCBFB53C0DCD29CF0019B3E5 /* JSDOMWindowShell.cpp in Sources */,
+                               1C5FAED10DCFD90100D58F78 /* JSJavaScriptCallFrame.cpp in Sources */,
+                               1C5FAEE70DCFDA6800D58F78 /* JSJavaScriptCallFrameCustom.cpp in Sources */,
                                2999869F0DD0DEEA00F8D261 /* AccessibilityListBoxOption.cpp in Sources */,
                                299986A10DD0DEEA00F8D261 /* AccessibilityListBox.cpp in Sources */,
                                BC34C33A0DD607DE00090123 /* AccessControlList.cpp in Sources */,
diff --git a/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp b/WebCore/bindings/js/JSJavaScriptCallFrameCustom.cpp
new file mode 100644 (file)
index 0000000..0eff55d
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSJavaScriptCallFrame.h"
+
+#include "JavaScriptCallFrame.h"
+#include <kjs/array_object.h>
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSJavaScriptCallFrame::evaluate(ExecState* exec, const List& args)
+{
+    if (!impl()->isValid())
+        return jsNull();
+    return impl()->evaluate(args[0]->toString(exec));
+}
+
+JSValue* JSJavaScriptCallFrame::scopeChain(ExecState* exec) const
+{
+    if (!impl()->isValid())
+        return jsNull();
+
+    const ScopeChain& chain = impl()->scopeChain();
+    ScopeChainIterator iter = chain.begin();
+    ScopeChainIterator end = chain.end();
+
+    // we must always have something in the scope chain
+    ASSERT(iter != end);
+
+    List list;
+    do {
+        list.append(*iter);
+        ++iter;
+    } while (iter != end);
+
+    return exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, list);
+}
+
+} // namespace WebCore
diff --git a/WebCore/page/JavaScriptCallFrame.cpp b/WebCore/page/JavaScriptCallFrame.cpp
new file mode 100644 (file)
index 0000000..2491c24
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JavaScriptCallFrame.h"
+
+#include "PlatformString.h"
+#include <kjs/JSGlobalObject.h>
+#include <kjs/interpreter.h>
+#include <kjs/object.h>
+#include <kjs/value.h>
+
+using namespace KJS;
+
+namespace WebCore {
+
+JavaScriptCallFrame::JavaScriptCallFrame(ExecState* exec, PassRefPtr<JavaScriptCallFrame> caller, int sourceID, int line)
+    : m_exec(exec)
+    , m_caller(caller)
+    , m_sourceID(sourceID)
+    , m_line(line)
+{
+}
+
+JavaScriptCallFrame* JavaScriptCallFrame::caller()
+{
+    return m_caller.get();
+}
+
+String JavaScriptCallFrame::functionName() const
+{
+    if (!m_exec || !m_exec->scopeNode())
+        return String();
+
+    FunctionImp* function = m_exec->function();
+    if (!function)
+        return String();
+
+    return String(function->functionName());
+}
+
+// Evaluate some JavaScript code in the context of this frame.
+// The code is evaluated as if by "eval", and the result is returned.
+// If there is an (uncaught) exception, it is returned as though _it_ were the result.
+
+// FIXME: If "script" contains var declarations, the machinery to handle local variables
+// efficiently in JavaScriptCore will not work properly. This could lead to crashes or
+// incorrect variable values. So this is not appropriate for evaluating arbitrary scripts.
+
+JSValue* JavaScriptCallFrame::evaluate(const UString& script) const
+{
+    if (!m_exec)
+        return jsNull();
+
+    JSLock lock;
+
+    ExecState* exec = m_exec;
+    JSGlobalObject* globalObject = exec->dynamicGlobalObject();
+
+    // find "eval"
+    JSObject* eval = 0;
+    if (exec->scopeNode()) {  // "eval" won't work without context (i.e. at global scope)
+        JSValue* v = globalObject->get(exec, "eval");
+        if (v->isObject() && static_cast<JSObject*>(v)->implementsCall())
+            eval = static_cast<JSObject*>(v);
+        else
+            // no "eval" - fallback operates on global exec state
+            exec = globalObject->globalExec();
+    }
+
+    JSValue* savedException = exec->exception();
+    exec->clearException();
+
+    // evaluate
+    JSValue* result = 0;
+    if (eval) {
+        List args;
+        args.append(jsString(script));
+        result = eval->call(exec, 0, args);
+    } else
+        // no "eval", or no context (i.e. global scope) - use global fallback
+        result = Interpreter::evaluate(exec, UString(), 0, script.data(), script.size(), globalObject).value();
+
+    if (exec->hadException())
+        result = exec->exception();    // (may be redundant depending on which eval path was used)
+    exec->setException(savedException);
+
+    return result;
+}
+
+} // namespace WebCore
diff --git a/WebCore/page/JavaScriptCallFrame.h b/WebCore/page/JavaScriptCallFrame.h
new file mode 100644 (file)
index 0000000..b172af0
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef JavaScriptCallFrame_h
+#define JavaScriptCallFrame_h
+
+#include <kjs/ExecState.h>
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+    class String;
+
+    class JavaScriptCallFrame : public RefCounted<JavaScriptCallFrame> {
+    public:
+        static PassRefPtr<JavaScriptCallFrame> create(KJS::ExecState* exec, PassRefPtr<JavaScriptCallFrame> caller, int sourceID, int line) { return adoptRef(new JavaScriptCallFrame(exec, caller, sourceID, line)); }
+
+        void invalidate() { m_exec = 0; }
+        bool isValid() const { return !!m_exec; }
+
+        KJS::ExecState* execState() const { return m_exec; }
+
+        JavaScriptCallFrame* caller();
+
+        int sourceIdentifier() const { return m_sourceID; }
+
+        int line() const { return m_line; }
+        void setLine(int line) { m_line = line; }
+
+        String functionName() const;
+        const KJS::ScopeChain& scopeChain() const { return m_exec->scopeChain(); }
+        KJS::JSValue* evaluate(const KJS::UString& script) const;
+
+    private:
+        JavaScriptCallFrame(KJS::ExecState*, PassRefPtr<JavaScriptCallFrame> caller, int sourceID, int line);
+
+        KJS::ExecState* m_exec;
+        RefPtr<JavaScriptCallFrame> m_caller;
+        int m_sourceID;
+        int m_line;
+    };
+
+} // namespace WebCore
+
+#endif // JavaScriptCallFrame_h
diff --git a/WebCore/page/JavaScriptCallFrame.idl b/WebCore/page/JavaScriptCallFrame.idl
new file mode 100644 (file)
index 0000000..39f40fa
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+module inspector {
+
+    interface JavaScriptCallFrame {
+        [Custom] void evaluate(in DOMString script);
+
+        readonly attribute JavaScriptCallFrame caller;
+        readonly attribute long sourceIdentifier;
+        readonly attribute long line;
+        readonly attribute [CustomGetter] Array scopeChain;
+        readonly attribute DOMString functionName;
+    };
+
+}