Bug 1363200 - JSAPI for realms: JS::Get/SetRealmPrivate(). r=sfink

The existing CompartmentPrivate struct will be split into two parts,
one part containing per-realm (i.e. per web page) data and one
containing per-compartment (i.e. per trust realm) data.

--HG--
extra : rebase_source : 8b5693d05b618cc7d7299f725b26d5535ee847f9
This commit is contained in:
Jason Orendorff 2017-05-22 14:56:02 -05:00
Родитель 5df09661ff
Коммит cb4a93f642
4 изменённых файлов: 23 добавлений и 0 удалений

Просмотреть файл

@ -59,6 +59,16 @@ GetRealmForCompartment(JSCompartment* compartment) {
return reinterpret_cast<Realm*>(compartment);
}
// Get the value of the "private data" internal field of the given Realm.
// This field is initially null and is set using SetRealmPrivate.
// It's a pointer to embeddding-specific data that SpiderMonkey never uses.
extern JS_PUBLIC_API(void*)
GetRealmPrivate(Realm* realm);
// Set the "private data" internal field of the given Realm.
extern JS_PUBLIC_API(void)
SetRealmPrivate(Realm* realm, void* data);
extern JS_PUBLIC_API(JSObject*)
GetRealmObjectPrototype(JSContext* cx);

Просмотреть файл

@ -67,6 +67,7 @@ JSCompartment::JSCompartment(Zone* zone, const JS::CompartmentOptions& options =
enterCompartmentDepth(0),
performanceMonitoring(runtime_),
data(nullptr),
realmData(nullptr),
allocationMetadataBuilder(nullptr),
lastAnimationTime(0),
regExps(zone),

Просмотреть файл

@ -691,6 +691,7 @@ struct JSCompartment
public:
void* data;
void* realmData;
private:
const js::AllocationMetadataBuilder *allocationMetadataBuilder;

Просмотреть файл

@ -34,6 +34,17 @@ gc::RealmNeedsSweep(JS::Realm* realm)
return JS::GetCompartmentForRealm(realm)->globalIsAboutToBeFinalized();
}
JS_PUBLIC_API(void*)
JS::GetRealmPrivate(JS::Realm* realm)
{
return GetCompartmentForRealm(realm)->realmData;
}
JS_PUBLIC_API(void)
JS::SetRealmPrivate(JS::Realm* realm, void* data)
{
GetCompartmentForRealm(realm)->realmData = data;
}
JS_PUBLIC_API(JSObject*)
JS::GetRealmObjectPrototype(JSContext* cx)