Commit 7c0ba747 authored by kmccullough@apple.com's avatar kmccullough@apple.com

2008-05-14 Kevin McCullough <kmccullough@apple.com>

        Reviewed by Adam.

        <rdar://problem/5770054> JavaScript profiler (10928)
        - Add support for interacting with the JavaScriptCore profiler.

        * ForwardingHeaders/profiler/FunctionCallProfile.h: Added.
        * ForwardingHeaders/profiler/Profile.h: Added.
        * GNUmakefile.am: Add the new files to all the projects.
        * WebCore.pro:
        * WebCore.vcproj/WebCore.vcproj:
        * WebCore.xcodeproj/project.pbxproj:
        * WebCoreSources.bkl:
        * page/InspectorController.cpp: Add the ability to retrieve all of the
        profiles in JavaScript from the InspectorController.
        (WebCore::allProfiles):
        (WebCore::InspectorController::windowScriptObjectAvailable):
        * page/JavaScriptFunctionCallProfile.cpp: Added. Wrapper around the JSC
        FunctionCallProfile.
        (WebCore::functionCallProfileCache): This cache makes sure we don't
        needlessly create duplicate wrappers around the same
        FunctionCallProfile*.
        (WebCore::getFunctionName): Callback to return the name of the function.
        (WebCore::getTotalTime): Callback to return the total time spent in the
        function.
        (WebCore::getSelfTime): Callback to return the time spent in self (total
        - time in children) in the function.
        (WebCore::getNumberOfCalls): Callback to return the number of times this
        function was called.
        (WebCore::getChildren): Callback to return the children of this function
        where the children are the functions this function called.
        (WebCore::finalize): Cleanup.
        (WebCore::functionCallProfileClass): Define the JSClassRef for this
        object.
        (WebCore::toJS): Create a conversion function to make a usable JSValue
        to wrap the FunctionCallProfile in JSC.
        * page/JavaScriptFunctionCallProfile.h: Added.
        * page/JavaScriptProfile.cpp: Added. Wrapper around the JSC Profile.
        (WebCore::profileCache): This cache makes sure we don't needlessly
        create duplicate wrappers aroudn the same Profile*.
        (WebCore::getHeadCallback): Callback to return the head of the graph of
        the functions profiled durring this profile's run.
        (WebCore::finalize):
        (WebCore::profileClass): Define the JSClassRef for this object.
        (WebCore::toJS): Create a conversion function to make a usable JSValue
        to wrap the Profile from JSC.
        * page/JavaScriptProfile.h: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@33460 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 31233a40
2008-05-14 Kevin McCullough <kmccullough@apple.com>
Reviewed by Adam.
<rdar://problem/5770054> JavaScript profiler (10928)
- Add support for interacting with the JavaScriptCore profiler.
* ForwardingHeaders/profiler/FunctionCallProfile.h: Added.
* ForwardingHeaders/profiler/Profile.h: Added.
* GNUmakefile.am: Add the new files to all the projects.
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* WebCoreSources.bkl:
* page/InspectorController.cpp: Add the ability to retrieve all of the
profiles in JavaScript from the InspectorController.
(WebCore::allProfiles):
(WebCore::InspectorController::windowScriptObjectAvailable):
* page/JavaScriptFunctionCallProfile.cpp: Added. Wrapper around the JSC
FunctionCallProfile.
(WebCore::functionCallProfileCache): This cache makes sure we don't
needlessly create duplicate wrappers around the same
FunctionCallProfile*.
(WebCore::getFunctionName): Callback to return the name of the function.
(WebCore::getTotalTime): Callback to return the total time spent in the
function.
(WebCore::getSelfTime): Callback to return the time spent in self (total
- time in children) in the function.
(WebCore::getNumberOfCalls): Callback to return the number of times this
function was called.
(WebCore::getChildren): Callback to return the children of this function
where the children are the functions this function called.
(WebCore::finalize): Cleanup.
(WebCore::functionCallProfileClass): Define the JSClassRef for this
object.
(WebCore::toJS): Create a conversion function to make a usable JSValue
to wrap the FunctionCallProfile in JSC.
* page/JavaScriptFunctionCallProfile.h: Added.
* page/JavaScriptProfile.cpp: Added. Wrapper around the JSC Profile.
(WebCore::profileCache): This cache makes sure we don't needlessly
create duplicate wrappers aroudn the same Profile*.
(WebCore::getHeadCallback): Callback to return the head of the graph of
the functions profiled durring this profile's run.
(WebCore::finalize):
(WebCore::profileClass): Define the JSClassRef for this object.
(WebCore::toJS): Create a conversion function to make a usable JSValue
to wrap the Profile from JSC.
* page/JavaScriptProfile.h: Added.
2008-05-14 David Hyatt <hyatt@apple.com>
Fix for bug https://bugs.webkit.org/show_bug.cgi?id=16130.
#include <JavaScriptCore/FunctionCallProfile.h>
#include <JavaScriptCore/Profile.h>
......@@ -856,6 +856,8 @@ webcore_sources += \
WebCore/page/InspectorController.cpp \
WebCore/page/JavaScriptCallFrame.cpp \
WebCore/page/JavaScriptDebugServer.cpp \
WebCore/page/JavaScriptProfile.cpp \
WebCore/page/JavaScriptFunctionCallProfile.cpp \
WebCore/page/Location.cpp \
WebCore/page/MouseEventWithHitTestResults.cpp \
WebCore/page/Navigator.cpp \
......
......@@ -791,6 +791,8 @@ SOURCES += \
page/InspectorController.cpp \
page/JavaScriptCallFrame.cpp \
page/JavaScriptDebugServer.cpp \
page/JavaScriptProfile.cpp \
page/JavaScriptFunctionCallProfile.cpp \
page/Location.cpp \
page/MouseEventWithHitTestResults.cpp \
page/Page.cpp \
......
......@@ -3383,6 +3383,22 @@
RelativePath="..\page\JavaScriptDebugServer.h"
>
</File>
<File
RelativePath="..\page\JavaScriptFunctionCallProfile.cpp"
>
</File>
<File
RelativePath="..\page\JavaScriptFunctionCallProfile.h"
>
</File>
<File
RelativePath="..\page\JavaScriptProfile.cpp"
>
</File>
<File
RelativePath="..\page\JavaScriptProfile.h"
>
</File>
<File
RelativePath="..\page\Location.cpp"
>
......
......@@ -1812,6 +1812,10 @@
93F9B7A00BA6032600854064 /* JSCDATASection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93F9B79E0BA6032600854064 /* JSCDATASection.cpp */; };
93F9B7A10BA6032600854064 /* JSCDATASection.h in Headers */ = {isa = PBXBuildFile; fileRef = 93F9B79F0BA6032600854064 /* JSCDATASection.h */; };
93FDAFCA0B11307400E2746F /* EditorInsertAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 93FDAFC90B11307400E2746F /* EditorInsertAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
95969B470DD8D21B00F653EE /* JavaScriptFunctionCallProfile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95969B430DD8D21B00F653EE /* JavaScriptFunctionCallProfile.cpp */; };
95969B480DD8D21B00F653EE /* JavaScriptFunctionCallProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 95969B440DD8D21B00F653EE /* JavaScriptFunctionCallProfile.h */; };
95969B490DD8D21B00F653EE /* JavaScriptProfile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95969B450DD8D21B00F653EE /* JavaScriptProfile.cpp */; };
95969B4A0DD8D21B00F653EE /* JavaScriptProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 95969B460DD8D21B00F653EE /* JavaScriptProfile.h */; };
A718760E0B2A120100A16ECE /* DragActions.h in Headers */ = {isa = PBXBuildFile; fileRef = A718760D0B2A120100A16ECE /* DragActions.h */; settings = {ATTRIBUTES = (Private, ); }; };
A71878900B2D04AC00A16ECE /* DragControllerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */; };
A7352C190B1BB89D00A986D0 /* RenderSVGBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7352C170B1BB89D00A986D0 /* RenderSVGBlock.cpp */; };
......@@ -6233,6 +6237,10 @@
93F9B79E0BA6032600854064 /* JSCDATASection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCDATASection.cpp; sourceTree = "<group>"; };
93F9B79F0BA6032600854064 /* JSCDATASection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCDATASection.h; sourceTree = "<group>"; };
93FDAFC90B11307400E2746F /* EditorInsertAction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = EditorInsertAction.h; sourceTree = "<group>"; };
95969B430DD8D21B00F653EE /* JavaScriptFunctionCallProfile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JavaScriptFunctionCallProfile.cpp; sourceTree = "<group>"; };
95969B440DD8D21B00F653EE /* JavaScriptFunctionCallProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptFunctionCallProfile.h; sourceTree = "<group>"; };
95969B450DD8D21B00F653EE /* JavaScriptProfile.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JavaScriptProfile.cpp; sourceTree = "<group>"; };
95969B460DD8D21B00F653EE /* JavaScriptProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptProfile.h; sourceTree = "<group>"; };
A718760D0B2A120100A16ECE /* DragActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DragActions.h; sourceTree = "<group>"; };
A718788F0B2D04AC00A16ECE /* DragControllerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragControllerMac.mm; sourceTree = "<group>"; };
A7352C170B1BB89D00A986D0 /* RenderSVGBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGBlock.cpp; sourceTree = "<group>"; };
......@@ -9068,6 +9076,10 @@
C02B14BF0D81E02A00D8A970 /* JavaScriptDebugListener.h */,
C02B14C00D81E02A00D8A970 /* JavaScriptDebugServer.cpp */,
C02B14C10D81E02A00D8A970 /* JavaScriptDebugServer.h */,
95969B430DD8D21B00F653EE /* JavaScriptFunctionCallProfile.cpp */,
95969B440DD8D21B00F653EE /* JavaScriptFunctionCallProfile.h */,
95969B450DD8D21B00F653EE /* JavaScriptProfile.cpp */,
95969B460DD8D21B00F653EE /* JavaScriptProfile.h */,
BCE1C41A0D982980003B02F2 /* Location.cpp */,
BCE1C4190D982980003B02F2 /* Location.h */,
BCE1C4220D9829F2003B02F2 /* Location.idl */,
......@@ -15092,6 +15104,8 @@
BC34C33D0DD607DE00090123 /* AccessItem.h in Headers */,
BC34C33F0DD607DE00090123 /* AccessItemRule.h in Headers */,
BC76AC130DD7AD5C00415F34 /* ParserUtilities.h in Headers */,
95969B480DD8D21B00F653EE /* JavaScriptFunctionCallProfile.h in Headers */,
95969B4A0DD8D21B00F653EE /* JavaScriptProfile.h in Headers */,
1A7FA6190DDA3B3A0028F8A5 /* NetworkStateNotifier.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
......@@ -16807,6 +16821,8 @@
BC34C33A0DD607DE00090123 /* AccessControlList.cpp in Sources */,
BC34C33C0DD607DE00090123 /* AccessItem.cpp in Sources */,
BC34C33E0DD607DE00090123 /* AccessItemRule.cpp in Sources */,
95969B470DD8D21B00F653EE /* JavaScriptFunctionCallProfile.cpp in Sources */,
95969B490DD8D21B00F653EE /* JavaScriptProfile.cpp in Sources */,
1A7FA61B0DDA3BBE0028F8A5 /* NetworkStateNotifier.cpp in Sources */,
1A7FA6490DDA3CBA0028F8A5 /* NetworkStateNotifierMac.cpp in Sources */,
);
......@@ -611,6 +611,8 @@ This file contains the list of files needed to build WebCore.
page/History.cpp
page/InspectorController.cpp
page/JavaScriptDebugServer.cpp
page/JavaScriptProfile.cpp
page/JavaScriptFunctionCallProfile.cpp
page/Location.cpp
page/MouseEventWithHitTestResults.cpp
page/Navigator.cpp
......
......@@ -68,7 +68,10 @@
#include <JavaScriptCore/JSLock.h>
#include <JavaScriptCore/JSRetainPtr.h>
#include <JavaScriptCore/JSStringRef.h>
#include <JavaScriptProfile.h>
#include <kjs/ustring.h>
#include <profiler/Profile.h>
#include <profiler/Profiler.h>
#include <wtf/RefCounted.h>
#if ENABLE(DATABASE)
......@@ -958,6 +961,47 @@ static JSValueRef removeBreakpoint(JSContextRef ctx, JSObjectRef /*function*/, J
return JSValueMakeUndefined(ctx);
}
#pragma mark -
#pragma mark Profiles
static JSValueRef allProfiles(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef /*thisObject*/, size_t /*argumentCount*/, const JSValueRef[] /*arguments*/, JSValueRef* exception)
{
KJS::JSLock lock;
const Vector<RefPtr<Profile> >& allProfiles = Profiler::profiler()->allProfiles();
JSObjectRef global = JSContextGetGlobalObject(ctx);
JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, jsStringRef("Array").get(), exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSValueRef pushProperty = JSObjectGetProperty(ctx, result, jsStringRef("push").get(), exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
for (size_t i = 0; i < allProfiles.size(); ++i) {
JSValueRef arg0 = toRef(toJS(toJS(ctx), allProfiles[i].get()));
JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
}
return result;
}
#pragma mark -
#pragma mark InspectorController Class
......@@ -1203,6 +1247,7 @@ void InspectorController::windowScriptObjectAvailable()
{ "startDebuggingAndReloadInspectedPage", WebCore::startDebuggingAndReloadInspectedPage, kJSPropertyAttributeNone },
{ "stopDebugging", WebCore::stopDebugging, kJSPropertyAttributeNone },
{ "debuggerAttached", WebCore::debuggerAttached, kJSPropertyAttributeNone },
{ "allProfiles", allProfiles, kJSPropertyAttributeNone },
{ "currentCallFrame", WebCore::currentCallFrame, kJSPropertyAttributeNone },
{ "pauseOnExceptions", WebCore::pauseOnExceptions, kJSPropertyAttributeNone },
{ "setPauseOnExceptions", WebCore::setPauseOnExceptions, kJSPropertyAttributeNone },
......
/*
* 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 "JavaScriptFunctionCallProfile.h"
#include "kjs_binding.h"
#include <profiler/FunctionCallProfile.h>
#include <JavaScriptCore/APICast.h>
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSContextRef.h>
#include <JavaScriptCore/JSRetainPtr.h>
#include <JavaScriptCore/JSStringRef.h>
#include <JavaScriptCore/Value.h>
using namespace KJS;
namespace WebCore {
// Cache
typedef HashMap<FunctionCallProfile*, JSValue*> FunctionCallProfileMap;
static FunctionCallProfileMap& functionCallProfileCache()
{
static FunctionCallProfileMap staticFunctionCallProfiles;
return staticFunctionCallProfiles;
}
// Static Values
static JSClassRef functionCallProfileClass();
static JSValueRef getFunctionName(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
if (!JSValueIsObjectOfClass(ctx, thisObject, functionCallProfileClass()))
return JSValueMakeUndefined(ctx);
FunctionCallProfile* functionCallProfile = static_cast<FunctionCallProfile*>(JSObjectGetPrivate(thisObject));
return JSValueMakeString(ctx, JSStringCreateWithCharacters(functionCallProfile->functionName().data(), functionCallProfile->functionName().size()));
}
static JSValueRef getTotalTime(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
KJS::JSLock lock;
if (!JSValueIsObjectOfClass(ctx, thisObject, functionCallProfileClass()))
return JSValueMakeUndefined(ctx);
FunctionCallProfile* functionCallProfile = static_cast<FunctionCallProfile*>(JSObjectGetPrivate(thisObject));
return JSValueMakeNumber(ctx, functionCallProfile->milliSecs());
}
static JSValueRef getSelfTime(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
KJS::JSLock lock;
if (!JSValueIsObjectOfClass(ctx, thisObject, functionCallProfileClass()))
return JSValueMakeUndefined(ctx);
FunctionCallProfile* functionCallProfile = static_cast<FunctionCallProfile*>(JSObjectGetPrivate(thisObject));
return JSValueMakeNumber(ctx, functionCallProfile->milliSecs());
}
static JSValueRef getNumberOfCalls(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
KJS::JSLock lock;
if (!JSValueIsObjectOfClass(ctx, thisObject, functionCallProfileClass()))
return JSValueMakeUndefined(ctx);
FunctionCallProfile* functionCallProfile = static_cast<FunctionCallProfile*>(JSObjectGetPrivate(thisObject));
return JSValueMakeNumber(ctx, functionCallProfile->numberOfCalls());
}
static JSValueRef getChildren(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
KJS::JSLock lock;
if (!JSValueIsObjectOfClass(ctx, thisObject, functionCallProfileClass()))
return JSValueMakeUndefined(ctx);
FunctionCallProfile* functionCallProfile = static_cast<FunctionCallProfile*>(JSObjectGetPrivate(thisObject));
const Deque<RefPtr<FunctionCallProfile> >& children = functionCallProfile->children();
JSObjectRef global = JSContextGetGlobalObject(ctx);
JSRetainPtr<JSStringRef> arrayString(Adopt, JSStringCreateWithUTF8CString("Array"));
JSValueRef arrayProperty = JSObjectGetProperty(ctx, global, arrayString.get(), exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef arrayConstructor = JSValueToObject(ctx, arrayProperty, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef result = JSObjectCallAsConstructor(ctx, arrayConstructor, 0, 0, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSRetainPtr<JSStringRef> pushString(Adopt, JSStringCreateWithUTF8CString("push"));
JSValueRef pushProperty = JSObjectGetProperty(ctx, result, pushString.get(), exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
JSObjectRef pushFunction = JSValueToObject(ctx, pushProperty, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
for (Deque<RefPtr<FunctionCallProfile> >::const_iterator it = children.begin(); it != children.end(); ++it) {
JSValueRef arg0 = toRef(toJS(toJS(ctx), (*it).get() ));
JSObjectCallAsFunction(ctx, pushFunction, result, 1, &arg0, exception);
if (exception && *exception)
return JSValueMakeUndefined(ctx);
}
return result;
}
static void finalize(JSObjectRef object)
{
FunctionCallProfile* functionCallProfile = static_cast<FunctionCallProfile*>(JSObjectGetPrivate(object));
functionCallProfileCache().remove(functionCallProfile);
functionCallProfile->deref();
}
JSClassRef functionCallProfileClass()
{
static JSStaticValue staticValues[] = {
{ "functionName", getFunctionName, 0, kJSPropertyAttributeNone },
{ "totalTime", getTotalTime, 0, kJSPropertyAttributeNone },
{ "selfTime", getSelfTime, 0, kJSPropertyAttributeNone },
{ "numberOfCalls", getNumberOfCalls, 0, kJSPropertyAttributeNone },
{ "children", getChildren, 0, kJSPropertyAttributeNone },
{ 0, 0, 0, 0 }
};
static JSClassDefinition classDefinition = {
0, kJSClassAttributeNone, "FunctionCallProfile", 0, staticValues, 0,
0, finalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static JSClassRef functionCallProfileClass = JSClassCreate(&classDefinition);
return functionCallProfileClass;
}
JSValue* toJS(ExecState* exec, FunctionCallProfile* functionCallProfile)
{
if (!functionCallProfile)
return jsNull();
JSValue* functionCallProfileWrapper = functionCallProfileCache().get(functionCallProfile);
if (functionCallProfileWrapper)
return functionCallProfileWrapper;
functionCallProfile->ref();
functionCallProfileWrapper = toJS(JSObjectMake(toRef(exec), functionCallProfileClass(), static_cast<void*>(functionCallProfile)));
functionCallProfileCache().set(functionCallProfile, functionCallProfileWrapper);
return functionCallProfileWrapper;
}
} // namespace WebCore
/*
* 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 JavaScriptFunctionCallProfile_h
#define JavaScriptFunctionCallProfile_h
#include <JavaScriptCore/JSBase.h>
namespace KJS {
class ExecState;
class FunctionCallProfile;
class JSValue;
}
namespace WebCore {
KJS::JSValue* toJS(KJS::ExecState*, KJS::FunctionCallProfile*);
} // namespace WebCore
#endif
/*
* 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 "JavaScriptProfile.h"
#include "JavaScriptFunctionCallProfile.h"
#include <profiler/Profile.h>
#include <JavaScriptCore/APICast.h>
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSStringRef.h>
#include <JavaScriptCore/Value.h>
#include <kjs/object.h>
using namespace KJS;
namespace WebCore {
// Cache
typedef HashMap<Profile*, JSValue*> ProfileMap;
static ProfileMap& profileCache()
{
static ProfileMap staticProfiles;
return staticProfiles;
}
// Static Values
static JSClassRef profileClass();
static JSValueRef getTitleCallback(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
if (!JSValueIsObjectOfClass(ctx, thisObject, profileClass()))
return JSValueMakeUndefined(ctx);
Profile* profile = static_cast<Profile*>(JSObjectGetPrivate(thisObject));
return JSValueMakeString(ctx, toRef(profile->title().rep()));
}
static JSValueRef getHeadCallback(JSContextRef ctx, JSObjectRef thisObject, JSStringRef propertyName, JSValueRef* exception)
{
if (!JSValueIsObjectOfClass(ctx, thisObject, profileClass()))
return JSValueMakeUndefined(ctx);
Profile* profile = static_cast<Profile*>(JSObjectGetPrivate(thisObject));
return toRef(toJS(toJS(ctx), profile->callTree()));
}
static void finalize(JSObjectRef object)
{
Profile* profile = static_cast<Profile*>(JSObjectGetPrivate(object));
profileCache().remove(profile);
profile->deref();
}
JSClassRef profileClass()
{
static JSStaticValue staticValues[] = {
{ "title", getTitleCallback, 0, kJSPropertyAttributeNone },
{ "head", getHeadCallback, 0, kJSPropertyAttributeNone },
{ 0, 0, 0, 0 }
};
static JSClassDefinition classDefinition = {
0, kJSClassAttributeNone, "Profile", 0, staticValues, 0,
0, finalize, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static JSClassRef profileClass = JSClassCreate(&classDefinition);
return profileClass;
}
JSValue* toJS(ExecState* exec, Profile* profile)
{
if (!profile)
return jsNull();
JSValue* profileWrapper = profileCache().get(profile);
if (profileWrapper)
return profileWrapper;
profile->ref();
profileWrapper = toJS(JSObjectMake(toRef(exec), profileClass(), static_cast<void*>(profile)));
profileCache().set(profile, profileWrapper);
return profileWrapper;
}
} // namespace WebCore
/*
* 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 JavaScriptProfile_h
#define JavaScriptProfile_h
#include <JavaScriptCore/JSBase.h>
namespace KJS {
class ExecState;
class JSValue;
class Profile;
}
namespace WebCore {
KJS::JSValue* toJS(KJS::ExecState*, KJS::Profile*);
} // namespace WebCore
#endif
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