/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
void RemoteObjectProxyBase::GetOrCreateProxyObject(
JSContext* aCx, void* aNative, const JSClass* aClasp,
JS::Handle<JSObject*> aTransplantTo, JS::MutableHandle<JSObject*> aProxy, bool& aNewObjectCreated) const {
xpc::CompartmentPrivate* priv =
xpc::CompartmentPrivate::Get(JS::CurrentGlobalOrNull(aCx));
xpc::CompartmentPrivate::RemoteProxyMap& map = priv->GetRemoteProxyMap(); if (auto result = map.lookup(aNative)) {
MOZ_RELEASE_ASSERT(!aTransplantTo, "GOCPO failed by finding an existing value");
aProxy.set(result->value());
// During a transplant, we put an object that is temporarily not a // proxy object into the map. Make sure that we don't return one of // these objects in the middle of a transplant.
MOZ_RELEASE_ASSERT(JS::GetClass(aProxy) == aClasp);
bool success; if (!JS_SetImmutablePrototype(aCx, obj, &success)) {
MOZ_RELEASE_ASSERT(!aTransplantTo, "GOCPO failed at JS_SetImmutablePrototype"); return;
}
MOZ_ASSERT(success);
aNewObjectCreated = true;
// If we're transplanting onto an object, we want to make sure that it does // not have the same class as aClasp to ensure that the release assert earlier // in this function will actually fire if we try to return a proxy object in // the middle of a transplant.
MOZ_RELEASE_ASSERT(!aTransplantTo || (JS::GetClass(aTransplantTo) != aClasp), "GOCPO failed by not changing the class");
if (!map.put(aNative, aTransplantTo ? aTransplantTo : obj)) {
MOZ_RELEASE_ASSERT(!aTransplantTo, "GOCPO failed at map.put"); return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.