2009-09-23 10:57:22 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2010-07-30 12:17:56 -07:00
|
|
|
* The Original Code is mozilla.org code.
|
2009-09-23 10:57:22 -07:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The Mozilla Foundation <http://www.mozilla.org/>.
|
2010-07-30 12:17:56 -07:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
2009-09-23 10:57:22 -07:00
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2010-07-30 12:17:56 -07:00
|
|
|
* Zack Weinberg <zweinberg@mozilla.com> (original author)
|
2009-09-23 10:57:22 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2010-07-30 12:17:56 -07:00
|
|
|
#include "PerfMeasurement.h"
|
|
|
|
#include "jsperf.h"
|
2010-06-10 11:11:40 -07:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2009-10-06 12:16:38 -07:00
|
|
|
#include "nsMemory.h"
|
|
|
|
|
2010-07-30 12:17:56 -07:00
|
|
|
#define JSPERF_CONTRACTID \
|
|
|
|
"@mozilla.org/jsperf;1"
|
2009-10-06 12:16:38 -07:00
|
|
|
|
2010-07-30 12:17:56 -07:00
|
|
|
#define JSPERF_CID \
|
|
|
|
{ 0x421c38e6, 0xaee0, 0x4509, \
|
|
|
|
{ 0xa0, 0x25, 0x13, 0x0f, 0x43, 0x78, 0x03, 0x5a } }
|
2009-09-23 10:57:22 -07:00
|
|
|
|
2009-09-23 10:57:22 -07:00
|
|
|
namespace mozilla {
|
2010-07-30 12:17:56 -07:00
|
|
|
namespace jsperf {
|
2009-09-23 10:57:22 -07:00
|
|
|
|
2009-10-06 12:16:38 -07:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(Module)
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(Module, nsIXPCScriptable)
|
|
|
|
|
|
|
|
Module::Module()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Module::~Module()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#define XPC_MAP_CLASSNAME Module
|
|
|
|
#define XPC_MAP_QUOTED_CLASSNAME "Module"
|
|
|
|
#define XPC_MAP_WANT_CALL
|
|
|
|
#define XPC_MAP_FLAGS nsIXPCScriptable::WANT_CALL
|
|
|
|
#include "xpc_map_end.h"
|
|
|
|
|
2010-03-17 10:48:48 -07:00
|
|
|
static JSBool
|
|
|
|
SealObjectAndPrototype(JSContext* cx, JSObject* parent, const char* name)
|
|
|
|
{
|
|
|
|
jsval prop;
|
|
|
|
if (!JS_GetProperty(cx, parent, name, &prop))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSObject* obj = JSVAL_TO_OBJECT(prop);
|
|
|
|
if (!JS_GetProperty(cx, obj, "prototype", &prop))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
JSObject* prototype = JSVAL_TO_OBJECT(prop);
|
|
|
|
return JS_SealObject(cx, obj, JS_FALSE) &&
|
|
|
|
JS_SealObject(cx, prototype, JS_FALSE);
|
|
|
|
}
|
|
|
|
|
2010-04-02 13:16:51 -07:00
|
|
|
static JSBool
|
2010-07-30 12:17:56 -07:00
|
|
|
InitAndSealPerfMeasurementClass(JSContext* cx, JSObject* global)
|
2009-10-06 12:16:38 -07:00
|
|
|
{
|
2010-07-30 12:17:56 -07:00
|
|
|
// Init the PerfMeasurement class
|
|
|
|
if (!JS::RegisterPerfMeasurement(cx, global))
|
2009-10-06 12:16:38 -07:00
|
|
|
return false;
|
|
|
|
|
2010-04-02 13:16:51 -07:00
|
|
|
// Seal up Object, Function, and Array and their prototypes. (This single
|
2010-07-30 12:17:56 -07:00
|
|
|
// object instance is shared amongst everyone who imports the jsperf module.)
|
2010-04-02 13:16:51 -07:00
|
|
|
if (!SealObjectAndPrototype(cx, global, "Object") ||
|
|
|
|
!SealObjectAndPrototype(cx, global, "Function") ||
|
|
|
|
!SealObjectAndPrototype(cx, global, "Array"))
|
2010-03-17 10:48:48 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Finally, seal the global object, for good measure. (But not recursively;
|
|
|
|
// this breaks things.)
|
2010-04-02 13:16:51 -07:00
|
|
|
return JS_SealObject(cx, global, JS_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Module::Call(nsIXPConnectWrappedNative* wrapper,
|
|
|
|
JSContext* cx,
|
|
|
|
JSObject* obj,
|
|
|
|
PRUint32 argc,
|
|
|
|
jsval* argv,
|
|
|
|
jsval* vp,
|
|
|
|
PRBool* _retval)
|
|
|
|
{
|
2010-07-30 12:17:56 -07:00
|
|
|
JSObject* scope = JS_GetScopeChain(cx);
|
|
|
|
if (!scope)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
JSObject* global = JS_GetGlobalForObject(cx, scope);
|
|
|
|
if (!global)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
*_retval = InitAndSealPerfMeasurementClass(cx, global);
|
2010-04-02 13:16:51 -07:00
|
|
|
return NS_OK;
|
2009-10-06 12:16:38 -07:00
|
|
|
}
|
2009-09-23 10:57:22 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2009-09-23 10:57:22 -07:00
|
|
|
|
2010-07-30 12:17:56 -07:00
|
|
|
NS_DEFINE_NAMED_CID(JSPERF_CID);
|
2010-06-10 11:11:40 -07:00
|
|
|
|
2010-07-30 12:17:56 -07:00
|
|
|
static const mozilla::Module::CIDEntry kPerfCIDs[] = {
|
|
|
|
{ &kJSPERF_CID, false, NULL, mozilla::jsperf::ModuleConstructor },
|
2010-06-10 11:11:40 -07:00
|
|
|
{ NULL }
|
2009-09-23 10:57:22 -07:00
|
|
|
};
|
|
|
|
|
2010-07-30 12:17:56 -07:00
|
|
|
static const mozilla::Module::ContractIDEntry kPerfContracts[] = {
|
|
|
|
{ JSPERF_CONTRACTID, &kJSPERF_CID },
|
2010-06-10 11:11:40 -07:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2010-07-30 12:17:56 -07:00
|
|
|
static const mozilla::Module kPerfModule = {
|
2010-06-10 11:11:40 -07:00
|
|
|
mozilla::Module::kVersion,
|
2010-07-30 12:17:56 -07:00
|
|
|
kPerfCIDs,
|
|
|
|
kPerfContracts
|
2010-06-10 11:11:40 -07:00
|
|
|
};
|
2009-09-23 10:57:22 -07:00
|
|
|
|
2010-07-30 12:17:56 -07:00
|
|
|
NSMODULE_DEFN(jsperf) = &kPerfModule;
|