mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1275315 part 1. Add a Realm.h that defines getters for some standard prototype objects. r=waldo
This commit is contained in:
parent
43c2748f66
commit
4eb8d252a4
42
js/public/Realm.h
Normal file
42
js/public/Realm.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
* 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/. */
|
||||
|
||||
/*
|
||||
* Ways to get various per-Realm objects. All the getters declared in this
|
||||
* header operate on the Realm corresponding to the current compartment on the
|
||||
* JSContext.
|
||||
*/
|
||||
|
||||
#ifndef js_Realm_h
|
||||
#define js_Realm_h
|
||||
|
||||
#include "jstypes.h"
|
||||
|
||||
struct JSContext;
|
||||
class JSObject;
|
||||
|
||||
namespace JS {
|
||||
|
||||
extern JS_PUBLIC_API(JSObject*)
|
||||
GetRealmObjectPrototype(JSContext* cx);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject*)
|
||||
GetRealmFunctionPrototype(JSContext* cx);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject*)
|
||||
GetRealmArrayPrototype(JSContext* cx);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject*)
|
||||
GetRealmErrorPrototype(JSContext* cx);
|
||||
|
||||
extern JS_PUBLIC_API(JSObject*)
|
||||
GetRealmIteratorPrototype(JSContext* cx);
|
||||
|
||||
} // namespace JS
|
||||
|
||||
#endif // js_Realm_h
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "js/HashTable.h"
|
||||
#include "js/Id.h"
|
||||
#include "js/Principals.h"
|
||||
#include "js/Realm.h"
|
||||
#include "js/RootingAPI.h"
|
||||
#include "js/TracingAPI.h"
|
||||
#include "js/Utility.h"
|
||||
|
@ -130,6 +130,7 @@ EXPORTS.js += [
|
||||
'../public/ProfilingFrameIterator.h',
|
||||
'../public/ProfilingStack.h',
|
||||
'../public/Proxy.h',
|
||||
'../public/Realm.h',
|
||||
'../public/RequiredDefines.h',
|
||||
'../public/RootingAPI.h',
|
||||
'../public/SliceBudget.h',
|
||||
@ -339,6 +340,7 @@ UNIFIED_SOURCES += [
|
||||
'vm/Printer.cpp',
|
||||
'vm/Probes.cpp',
|
||||
'vm/ProxyObject.cpp',
|
||||
'vm/Realm.cpp',
|
||||
'vm/ReceiverGuard.cpp',
|
||||
'vm/RegExpObject.cpp',
|
||||
'vm/RegExpStatics.cpp',
|
||||
|
@ -343,6 +343,10 @@ class GlobalObject : public NativeObject
|
||||
return &self->getPrototype(JSProto_Object).toObject().as<NativeObject>();
|
||||
}
|
||||
|
||||
static NativeObject* getOrCreateObjectPrototype(JSContext* cx, Handle<GlobalObject*> global) {
|
||||
return global->getOrCreateObjectPrototype(cx);
|
||||
}
|
||||
|
||||
NativeObject* getOrCreateFunctionPrototype(JSContext* cx) {
|
||||
if (functionObjectClassesInitialized())
|
||||
return &getPrototype(JSProto_Function).toObject().as<NativeObject>();
|
||||
@ -352,6 +356,10 @@ class GlobalObject : public NativeObject
|
||||
return &self->getPrototype(JSProto_Function).toObject().as<NativeObject>();
|
||||
}
|
||||
|
||||
static NativeObject* getOrCreateFunctionPrototype(JSContext* cx, Handle<GlobalObject*> global) {
|
||||
return global->getOrCreateFunctionPrototype(cx);
|
||||
}
|
||||
|
||||
static NativeObject* getOrCreateArrayPrototype(JSContext* cx, Handle<GlobalObject*> global) {
|
||||
if (!ensureConstructor(cx, global, JSProto_Array))
|
||||
return nullptr;
|
||||
|
48
js/src/vm/Realm.cpp
Normal file
48
js/src/vm/Realm.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
* 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/. */
|
||||
|
||||
#include "js/Realm.h"
|
||||
|
||||
#include "jscntxt.h"
|
||||
|
||||
#include "vm/GlobalObject.h"
|
||||
|
||||
using namespace js;
|
||||
|
||||
JS_PUBLIC_API(JSObject*)
|
||||
JS::GetRealmObjectPrototype(JSContext* cx)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return GlobalObject::getOrCreateObjectPrototype(cx, cx->global());
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject*)
|
||||
JS::GetRealmFunctionPrototype(JSContext* cx)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return GlobalObject::getOrCreateFunctionPrototype(cx, cx->global());
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject*)
|
||||
JS::GetRealmArrayPrototype(JSContext* cx)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return GlobalObject::getOrCreateArrayPrototype(cx, cx->global());
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject*)
|
||||
JS::GetRealmErrorPrototype(JSContext* cx)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return GlobalObject::getOrCreateCustomErrorPrototype(cx, cx->global(), JSEXN_ERR);
|
||||
}
|
||||
|
||||
JS_PUBLIC_API(JSObject*)
|
||||
JS::GetRealmIteratorPrototype(JSContext* cx)
|
||||
{
|
||||
CHECK_REQUEST(cx);
|
||||
return GlobalObject::getOrCreateIteratorPrototype(cx, cx->global());
|
||||
}
|
Loading…
Reference in New Issue
Block a user