Bug 921478 - Remove BackstagePass IDB constructor resolve hook and use Cu.importGlobalProperties. r=bholley,bent

--HG--
rename : dom/indexedDB/test/test_globalObjects.xul => dom/indexedDB/test/test_globalObjects_chrome.xul
rename : dom/indexedDB/test/test_globalObjects.html => dom/indexedDB/test/test_globalObjects_content.html
rename : dom/indexedDB/test/unit/test_globalObjects.js => dom/indexedDB/test/unit/test_globalObjects_xpc.js
This commit is contained in:
Jan Varga 2013-11-19 08:36:12 +01:00
parent bd6038d32e
commit 8f8a999182
26 changed files with 153 additions and 232 deletions

View File

@ -20,6 +20,7 @@ this.EXPORTED_SYMBOLS = ["IndexedDBHelper"];
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.importGlobalProperties(["indexedDB"]);
this.IndexedDBHelper = function IndexedDBHelper() {}

View File

@ -18,6 +18,7 @@ const Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
Cu.importGlobalProperties(["indexedDB"]);
const DB_NAME = "contacts";
const DB_VERSION = 18;

View File

@ -148,6 +148,7 @@ function makeFailure(reason) {
const {Cc, Ci, Cu} = SpecialPowers;
Cu.import("resource://gre/modules/ContactDB.jsm", window);
Cu.importGlobalProperties(["indexedDB"]);
let cdb = new ContactDB();
cdb.init();

View File

@ -111,35 +111,6 @@ mozilla::StaticRefPtr<IndexedDatabaseManager> gInstance;
mozilla::Atomic<int32_t> gInitialized(0);
mozilla::Atomic<int32_t> gClosed(0);
// See ResolveConstructors below.
struct ConstructorInfo {
const char* const name;
JS::Handle<JSObject*> (* const resolve)(JSContext*, JS::Handle<JSObject*>,
bool);
jsid id;
};
ConstructorInfo gConstructorInfo[] = {
#define BINDING_ENTRY(_name) \
{ #_name, _name##Binding::GetConstructorObject, JSID_VOID },
BINDING_ENTRY(IDBCursor)
BINDING_ENTRY(IDBCursorWithValue)
BINDING_ENTRY(IDBDatabase)
BINDING_ENTRY(IDBFactory)
BINDING_ENTRY(IDBFileHandle)
BINDING_ENTRY(IDBIndex)
BINDING_ENTRY(IDBKeyRange)
BINDING_ENTRY(IDBObjectStore)
BINDING_ENTRY(IDBOpenDBRequest)
BINDING_ENTRY(IDBRequest)
BINDING_ENTRY(IDBTransaction)
BINDING_ENTRY(IDBVersionChangeEvent)
#undef BINDING_ENTRY
};
class AsyncDeleteFileRunnable MOZ_FINAL : public nsIRunnable
{
public:
@ -207,53 +178,6 @@ struct MOZ_STACK_CLASS InvalidateInfo
const nsACString& pattern;
};
bool
GetIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
JS::MutableHandle<JS::Value> aResult)
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome(), "Only for chrome!");
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
"Not a global object!");
nsRefPtr<IDBFactory> factory;
if (NS_FAILED(IDBFactory::Create(aCx, aGlobal, nullptr,
getter_AddRefs(factory)))) {
return false;
}
MOZ_ASSERT(factory, "This should never fail for chrome!");
return !!WrapNewBindingObject(aCx, aGlobal, factory, aResult);
}
bool
IndexedDBLazyGetter(JSContext* aCx, JS::Handle<JSObject*> aGlobal,
JS::Handle<jsid> aId, JS::MutableHandle<JS::Value> aVp)
{
MOZ_ASSERT(nsContentUtils::IsCallerChrome(), "Only for chrome!");
MOZ_ASSERT(JSID_IS_STRING(aId), "Bad id!");
MOZ_ASSERT(JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(aId), IDB_STR),
"Bad id!");
JS::Rooted<JSObject*> global(aCx, CheckedUnwrap(aGlobal,
/* stopAtOuter = */ false));
NS_ENSURE_TRUE(global, false);
NS_ENSURE_TRUE(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL, false);
JS::Rooted<JS::Value> indexedDB(aCx);
if (!GetIndexedDB(aCx, global, &indexedDB)) {
return false;
}
if (!JS_DefinePropertyById(aCx, global, aId, indexedDB, nullptr, nullptr,
JSPROP_ENUMERATE)) {
return false;
}
aVp.set(indexedDB);
return true;
}
} // anonymous namespace
IndexedDatabaseManager::IndexedDatabaseManager()
@ -482,32 +406,39 @@ IndexedDatabaseManager::TabContextMayAccessOrigin(const TabContext& aContext,
// static
bool
IndexedDatabaseManager::DefineConstructors(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
{
MOZ_ASSERT(NS_IsMainThread());
for (uint32_t i = 0; i < mozilla::ArrayLength(gConstructorInfo); i++) {
if (!gConstructorInfo[i].resolve(aCx, aGlobal, true)) {
return false;
}
}
return true;
}
// static
bool
IndexedDatabaseManager::DefineIndexedDBGetter(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
IndexedDatabaseManager::DefineIndexedDB(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(nsContentUtils::IsCallerChrome(), "Only for chrome!");
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
"Passed object is not a global object!");
if (!IDBCursorBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBCursorWithValueBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBDatabaseBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBFactoryBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBFileHandleBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBIndexBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBKeyRangeBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBObjectStoreBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBOpenDBRequestBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBRequestBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBTransactionBinding::GetConstructorObject(aCx, aGlobal) ||
!IDBVersionChangeEventBinding::GetConstructorObject(aCx, aGlobal)) {
return false;
}
nsRefPtr<IDBFactory> factory;
if (NS_FAILED(IDBFactory::Create(aCx, aGlobal, nullptr,
getter_AddRefs(factory)))) {
return false;
}
MOZ_ASSERT(factory, "This should never fail for chrome!");
JS::Rooted<JS::Value> indexedDB(aCx);
if (!GetIndexedDB(aCx, aGlobal, &indexedDB)) {
if (!WrapNewBindingObject(aCx, aGlobal, factory, &indexedDB)) {
return false;
}
@ -515,20 +446,6 @@ IndexedDatabaseManager::DefineIndexedDBGetter(JSContext* aCx,
JSPROP_ENUMERATE);
}
// static
bool
IndexedDatabaseManager::DefineIndexedDBLazyGetter(JSContext* aCx,
JS::Handle<JSObject*> aGlobal)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(nsContentUtils::IsCallerChrome(), "Only for chrome!");
MOZ_ASSERT(js::GetObjectClass(aGlobal)->flags & JSCLASS_DOM_GLOBAL,
"Passed object is not a global object!");
return JS_DefineProperty(aCx, aGlobal, IDB_STR, JSVAL_VOID,
IndexedDBLazyGetter, nullptr, 0);
}
// static
bool
IndexedDatabaseManager::IsClosed()
@ -749,7 +666,7 @@ IndexedDatabaseManager::InitWindowless(const jsval& aGlobal, JSContext* aCx)
return NS_ERROR_FAILURE;
}
if (!DefineConstructors(aCx, global) || !DefineIndexedDBGetter(aCx, global)) {
if (!DefineIndexedDB(aCx, global)) {
return NS_ERROR_FAILURE;
}
@ -1001,49 +918,3 @@ GetFileReferencesHelper::Run()
return NS_OK;
}
BEGIN_INDEXEDDB_NAMESPACE
bool
ResolveConstructors(JSContext* aCx, JS::Handle<JSObject*> aObj,
JS::Handle<jsid> aId, JS::MutableHandle<JSObject*> aObjp)
{
MOZ_ASSERT(NS_IsMainThread());
// The first time this function is called we need to intern all the strings we
// care about.
if (JSID_IS_VOID(gConstructorInfo[0].id)) {
for (uint32_t i = 0; i < mozilla::ArrayLength(gConstructorInfo); i++) {
JS::Rooted<JSString*> str(aCx,
JS_InternString(aCx, gConstructorInfo[i].name));
if (!str) {
NS_WARNING("Failed to intern string!");
while (i) {
gConstructorInfo[--i].id = JSID_VOID;
}
return false;
}
gConstructorInfo[i].id = INTERNED_STRING_TO_JSID(aCx, str);
}
}
// Now resolve.
for (uint32_t i = 0; i < mozilla::ArrayLength(gConstructorInfo); i++) {
if (gConstructorInfo[i].id == aId) {
JS::Rooted<JSObject*> constructor(aCx,
gConstructorInfo[i].resolve(aCx, aObj, true));
if (!constructor) {
return false;
}
aObjp.set(aObj);
return true;
}
}
// Not resolved.
aObjp.set(nullptr);
return true;
}
END_INDEXEDDB_NAMESPACE

View File

@ -140,13 +140,7 @@ public:
const nsACString& aOrigin);
static bool
DefineConstructors(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
static bool
DefineIndexedDBGetter(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
static bool
DefineIndexedDBLazyGetter(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
DefineIndexedDB(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
private:
IndexedDatabaseManager();
@ -176,10 +170,6 @@ private:
static mozilla::Atomic<int32_t> sLowDiskSpaceMode;
};
bool
ResolveConstructors(JSContext* aCx, JS::Handle<JSObject*> aObj,
JS::Handle<jsid> aId, JS::MutableHandle<JSObject*> aObjp);
END_INDEXEDDB_NAMESPACE
#endif /* mozilla_dom_indexeddb_indexeddatabasemanager_h__ */

View File

@ -1,4 +1,5 @@
[DEFAULT]
support-files = chromeHelpers.js
[test_globalObjects.xul]
[test_globalObjects_chrome.xul]
[test_globalObjects_other.xul]

View File

@ -7,11 +7,15 @@ const { 'classes': Cc, 'interfaces': Ci, 'utils': Cu } = Components;
let testGenerator = testSteps();
function runTest()
{
SimpleTest.waitForExplicitFinish();
if (!window.runTest) {
window.runTest = function()
{
Cu.importGlobalProperties(["indexedDB"]);
testGenerator.next();
SimpleTest.waitForExplicitFinish();
testGenerator.next();
}
}
function finishTest()

View File

@ -58,7 +58,7 @@ support-files =
[test_filehandle_store_snapshot.html]
[test_getAll.html]
[test_get_filehandle.html]
[test_globalObjects.html]
[test_globalObjects_content.html]
[test_global_data.html]
[test_index_empty_keyPath.html]
[test_index_getAll.html]

View File

@ -0,0 +1,43 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<window title="Mozilla Bug 832883"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
onload="runTest();">
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript;version=1.7">
<![CDATA[
function testSteps() {
const name = window.location.pathname;
// Test for IDBKeyRange and indexedDB availability in chrome windows.
var keyRange = IDBKeyRange.only(42);
ok(keyRange, "Got keyRange");
var request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
ok(db, "Got database");
finishTest();
yield undefined;
}
]]>
</script>
<script type="text/javascript;version=1.7" src="chromeHelpers.js"></script>
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=832883"
target="_blank">Mozilla Bug 832883</a>
</body>
</window>

View File

@ -14,20 +14,6 @@
<script type="application/javascript;version=1.7">
<![CDATA[
function testSteps() {
const name = window.location.pathname;
// Test for IDBKeyRange and indexedDB availability in chrome windows.
var keyRange = IDBKeyRange.only(42);
ok(keyRange, "Got keyRange");
var request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
ok(db, "Got database");
// Test for IDBKeyRange and indexedDB availability in bootstrap files.
let test = Cc["@mozilla.org/dom/indexeddb/GlobalObjectsComponent;1"].
createInstance(Ci.nsISupports).wrappedJSObject;
@ -60,6 +46,12 @@
finishTest();
yield undefined;
}
window.runTest = function() {
SimpleTest.waitForExplicitFinish();
testGenerator.next();
}
]]>
</script>

View File

@ -18,6 +18,8 @@ function finishTest()
function run_test() {
const name = "Splendid Test";
Cu.importGlobalProperties(["indexedDB"]);
do_test_pending();
let keyRange = IDBKeyRange.only(42);

View File

@ -3,7 +3,10 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.importGlobalProperties(["indexedDB"]);
function GlobalObjectsComponent() {
this.wrappedJSObject = this;

View File

@ -3,6 +3,8 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
Components.utils.importGlobalProperties(["indexedDB"]);
this.EXPORTED_SYMBOLS = [
"GlobalObjectsModule"
];

View File

@ -38,15 +38,19 @@ function run_test() {
runTest();
};
function runTest()
{
// XPCShell does not get a profile by default.
do_get_profile();
if (!this.runTest) {
this.runTest = function()
{
// XPCShell does not get a profile by default.
do_get_profile();
enableExperimental();
enableExperimental();
do_test_pending();
testGenerator.next();
Cu.importGlobalProperties(["indexedDB"]);
do_test_pending();
testGenerator.next();
}
}
function finishTest()

View File

@ -18,8 +18,9 @@
[test_deleteDatabase_interactions.js]
[test_event_source.js]
[test_getAll.js]
[test_globalObjects.js]
[test_globalObjects_ipc.js]
[test_globalObjects_other.js]
[test_globalObjects_xpc.js]
[test_global_data.js]
[test_index_empty_keyPath.js]
[test_index_getAll.js]

View File

@ -7,8 +7,6 @@ var testGenerator = testSteps();
function testSteps()
{
const name = "Splendid Test";
let ioService =
Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
@ -18,18 +16,6 @@ function testSteps()
return uri.spec;
}
// Test for IDBKeyRange and indexedDB availability in xpcshell.
let keyRange = IDBKeyRange.only(42);
ok(keyRange, "Got keyRange");
let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
ok(db, "Got database");
// Test for IDBKeyRange and indexedDB availability in JS modules.
Cu.import(getSpec("GlobalObjectsModule.jsm"));
let test = new GlobalObjectsModule();
@ -65,3 +51,10 @@ function testSteps()
finishTest();
yield undefined;
}
this.runTest = function() {
do_get_profile();
do_test_pending();
testGenerator.next();
}

View File

@ -0,0 +1,26 @@
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var testGenerator = testSteps();
function testSteps()
{
const name = "Splendid Test";
// Test for IDBKeyRange and indexedDB availability in xpcshell.
let keyRange = IDBKeyRange.only(42);
ok(keyRange, "Got keyRange");
let request = indexedDB.open(name, 1);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield undefined;
let db = event.target.result;
ok(db, "Got database");
finishTest();
yield undefined;
}

View File

@ -28,10 +28,11 @@ support-files =
[test_deleteDatabase_interactions.js]
[test_event_source.js]
[test_getAll.js]
[test_globalObjects.js]
[test_globalObjects_ipc.js]
# FIXME/bug 575918: out-of-process xpcshell is broken on OS X
skip-if = os == "mac" || os == "android"
#skip-if = os == "mac" || os == "android"
[test_globalObjects_other.js]
[test_globalObjects_xpc.js]
[test_global_data.js]
[test_index_empty_keyPath.js]
[test_index_getAll.js]

View File

@ -9,6 +9,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/PhoneNumberUtils.jsm");
Cu.importGlobalProperties(["indexedDB"]);
const RIL_MOBILEMESSAGEDATABASESERVICE_CONTRACTID =
"@mozilla.org/mobilemessage/rilmobilemessagedatabaseservice;1";

View File

@ -13,6 +13,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
Cu.importGlobalProperties(["indexedDB"]);
const DB_NAME = "net_stats";
const DB_VERSION = 3;

View File

@ -23,6 +23,7 @@ Cu.import("resource://gre/modules/IndexedDBHelper.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
Cu.importGlobalProperties(["indexedDB"]);
XPCOMUtils.defineLazyModuleGetter(this, "AlarmService",
"resource://gre/modules/AlarmService.jsm");

View File

@ -948,8 +948,7 @@ bool
xpc::GlobalProperties::Define(JSContext *cx, JS::HandleObject obj)
{
if (indexedDB && AccessCheck::isChrome(obj) &&
(!IndexedDatabaseManager::DefineConstructors(cx, obj) ||
!IndexedDatabaseManager::DefineIndexedDBGetter(cx, obj)))
!IndexedDatabaseManager::DefineIndexedDB(cx, obj))
return false;
if (XMLHttpRequest &&

View File

@ -10,11 +10,9 @@
#include "nsDOMClassInfo.h"
#include "nsIPrincipal.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/dom/workers/Workers.h"
using mozilla::dom::workers::ResolveWorkerClasses;
namespace indexedDB = mozilla::dom::indexedDB;
NS_INTERFACE_MAP_BEGIN(BackstagePass)
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
@ -75,14 +73,6 @@ BackstagePass::NewResolve(nsIXPConnectWrappedNative *wrapper,
return NS_OK;
}
*_retval = indexedDB::ResolveConstructors(cx, obj, id, &objp);
NS_ENSURE_TRUE(*_retval, NS_ERROR_FAILURE);
if (objp) {
*objpArg = objp;
return NS_OK;
}
return NS_OK;
}

View File

@ -515,7 +515,6 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
MOZ_ASSERT(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL);
// Init WebIDL binding constructors wanted on all XPConnect globals.
// Additional bindings may be created lazily, see BackstagePass::NewResolve.
//
// XXX Please do not add any additional classes here without the approval of
// the XPConnect module owner.
@ -525,12 +524,6 @@ nsXPConnect::InitClassesWithNewWrappedGlobal(JSContext * aJSContext,
return UnexpectedFailure(NS_ERROR_FAILURE);
}
if (nsContentUtils::IsSystemPrincipal(aPrincipal) &&
!IndexedDatabaseManager::DefineIndexedDBLazyGetter(aJSContext,
global)) {
return UnexpectedFailure(NS_ERROR_FAILURE);
}
wrappedGlobal.forget(_retval);
return NS_OK;
}

View File

@ -537,7 +537,7 @@
"dom/indexedDB/test/test_filehandle_store_snapshot.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_getAll.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_get_filehandle.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_globalObjects.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_globalObjects_content.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_global_data.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_index_empty_keyPath.html": "Bug 931116, b2g desktop specific, initial triage",
"dom/indexedDB/test/test_index_getAll.html": "Bug 931116, b2g desktop specific, initial triage",