mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
cc81aca6b2
- Bug 1236321 - Annotate intentional switch fallthroughs to suppress -Wimplicit-fallthrough warnings in js/. r=luke (32d46328ef) - Bug 1236552 - Odin: handle unfinished AsmJSModuleObject in addSizeOfMisc (r=bbouvier) (dafbd77b10) - Bug 1229399: Make writing the IR fallible, provide a fallible readingAPI; r=luke (cbc536c3fa) - Bug 1237272 - Only for Coverity - check arg1, arg2 and arg3 for validity. r=luke (1456e58951) - Bug 1229399: Split FuncIR into Bytecode/Encoder/Decoder/FuncBytecode; r=luke (9f438b4d5f) - Bug 1237508 - Odin: make AsmJSModule derive wasm::Module (r=bbouvier) (0186bf908b) - Bug 1238195 - Switch over some AutoVectorRooters to Rooted<TraceableVector>s and fill in some missing support (r=terrence) (b556fdc27e) - Bug 1234193 - IsRelazifiableFunction: Return false when we report an error. r=jandem (bd3c33e1e6) - Bug 1221361: Mark SetARMHwCapFlags as unsafe for fuzzing; r=jolesen (3134febc32) - Bug 1236564 - Fix various minor issues with getting/setting GC parameters r=terrence (45e251eba7) - Bug 1235237 - Annotate intentional switch fallthrough to suppress -Wimplicit-fallthrough warning in storage/. r=mak (f81714fdab) - Bug 1235236 - Annotate intentional switch fallthrough to suppress -Wimplicit-fallthrough warning in modules/libjar/. r=aklotz (f3a210802b) - Bug 1236324 - Annotate intentional switch fallthroughs to suppress -Wimplicit-fallthrough warnings in toolkit/components/places/. r=mak (f2d09b5041) - Bug 1238711 - Rename TraceableVector to GCVector; r=sfink Bug 1237153 - Fix gcparam() parameter verification to not allow negative numbers r=terrence (deccfd7f01) - Bug 1235092 - Part 1: Optimize spread call with rest parameter. r=efaust (e6cc1294d1) - Bug 1235092 - Part 2: Support allowContentSpread in the optimization for spread call with rest parameter. r=efaust (31c881893d) - Bug 1235092 - Part 3: Root function in BytecodeEmitter::isRestParameter. r=bustage (ede37f48b6) - Bug 1233152 - Use PersistentRooted for ParseTask script and sourceObject. r=terrence (d99d9b81fb) - Bug 1236476: Report out of memory in ExpandErrorArgumentsVA; r=jandem (6a2327222c) - Bug 1239601 - improve the UniquePtr situation (r=jorendorff) (640322c8c1) - Bug 1239724: Introduce RegExp registers to non-ion builds; r=arai (f2d837e65b) - Bug 1137624 - Remove ArrayJoin code duplication, and use a correct alias set. r=jandem (ab8a98a5e3) - Bug 1237284: Make SIMD names more consistent in MCallOptimize; r=jolesen (d50f74a31e) - Bug 1238582 - Fix spurious assertion failure in array sort due to over-eager OOM simulation r=jandem (587f4976e5) - Bug 1235874 - handle null filename in DescribeScriptedCaller (r=sunfish) (b347469108) - Bug 1239601 - improve the UniquePtr situation (r=jandem) (a8b9f15dcb)
334 lines
11 KiB
C++
334 lines
11 KiB
C++
/* -*- 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/. */
|
|
|
|
#ifndef builtin_ModuleObject_h
|
|
#define builtin_ModuleObject_h
|
|
|
|
#include "jsapi.h"
|
|
#include "jsatom.h"
|
|
|
|
#include "gc/Zone.h"
|
|
|
|
#include "js/GCVector.h"
|
|
|
|
#include "vm/NativeObject.h"
|
|
#include "vm/ProxyObject.h"
|
|
|
|
namespace js {
|
|
|
|
class ModuleEnvironmentObject;
|
|
class ModuleObject;
|
|
|
|
namespace frontend {
|
|
class ParseNode;
|
|
} /* namespace frontend */
|
|
|
|
typedef Rooted<ModuleObject*> RootedModuleObject;
|
|
typedef Handle<ModuleObject*> HandleModuleObject;
|
|
typedef Rooted<ModuleEnvironmentObject*> RootedModuleEnvironmentObject;
|
|
typedef Handle<ModuleEnvironmentObject*> HandleModuleEnvironmentObject;
|
|
|
|
class ImportEntryObject : public NativeObject
|
|
{
|
|
public:
|
|
enum
|
|
{
|
|
ModuleRequestSlot = 0,
|
|
ImportNameSlot,
|
|
LocalNameSlot,
|
|
SlotCount
|
|
};
|
|
|
|
static const Class class_;
|
|
static JSObject* initClass(JSContext* cx, HandleObject obj);
|
|
static bool isInstance(HandleValue value);
|
|
static ImportEntryObject* create(JSContext* cx,
|
|
HandleAtom moduleRequest,
|
|
HandleAtom importName,
|
|
HandleAtom localName);
|
|
JSAtom* moduleRequest() const;
|
|
JSAtom* importName() const;
|
|
JSAtom* localName() const;
|
|
};
|
|
|
|
typedef Rooted<ImportEntryObject*> RootedImportEntryObject;
|
|
typedef Handle<ImportEntryObject*> HandleImportEntryObject;
|
|
|
|
class ExportEntryObject : public NativeObject
|
|
{
|
|
public:
|
|
enum
|
|
{
|
|
ExportNameSlot = 0,
|
|
ModuleRequestSlot,
|
|
ImportNameSlot,
|
|
LocalNameSlot,
|
|
SlotCount
|
|
};
|
|
|
|
static const Class class_;
|
|
static JSObject* initClass(JSContext* cx, HandleObject obj);
|
|
static bool isInstance(HandleValue value);
|
|
static ExportEntryObject* create(JSContext* cx,
|
|
HandleAtom maybeExportName,
|
|
HandleAtom maybeModuleRequest,
|
|
HandleAtom maybeImportName,
|
|
HandleAtom maybeLocalName);
|
|
JSAtom* exportName() const;
|
|
JSAtom* moduleRequest() const;
|
|
JSAtom* importName() const;
|
|
JSAtom* localName() const;
|
|
};
|
|
|
|
typedef Rooted<ExportEntryObject*> RootedExportEntryObject;
|
|
typedef Handle<ExportEntryObject*> HandleExportEntryObject;
|
|
|
|
class IndirectBindingMap
|
|
{
|
|
public:
|
|
explicit IndirectBindingMap(Zone* zone);
|
|
bool init();
|
|
|
|
void trace(JSTracer* trc);
|
|
|
|
bool putNew(JSContext* cx, HandleId name,
|
|
HandleModuleEnvironmentObject environment, HandleId localName);
|
|
|
|
size_t count() const {
|
|
return map_.count();
|
|
}
|
|
|
|
bool has(jsid name) const {
|
|
return map_.has(name);
|
|
}
|
|
|
|
bool lookup(jsid name, ModuleEnvironmentObject** envOut, Shape** shapeOut) const;
|
|
|
|
template <typename Func>
|
|
void forEachExportedName(Func func) const {
|
|
for (auto r = map_.all(); !r.empty(); r.popFront())
|
|
func(r.front().key());
|
|
}
|
|
|
|
private:
|
|
struct Binding
|
|
{
|
|
Binding(ModuleEnvironmentObject* environment, Shape* shape);
|
|
RelocatablePtr<ModuleEnvironmentObject*> environment;
|
|
RelocatablePtrShape shape;
|
|
};
|
|
|
|
typedef HashMap<jsid, Binding, JsidHasher, ZoneAllocPolicy> Map;
|
|
|
|
Map map_;
|
|
};
|
|
|
|
class ModuleNamespaceObject : public ProxyObject
|
|
{
|
|
public:
|
|
static bool isInstance(HandleValue value);
|
|
static ModuleNamespaceObject* create(JSContext* cx, HandleModuleObject module);
|
|
|
|
ModuleObject& module();
|
|
ArrayObject& exports();
|
|
IndirectBindingMap& bindings();
|
|
|
|
bool addBinding(JSContext* cx, HandleAtom exportedName, HandleModuleObject targetModule,
|
|
HandleAtom localName);
|
|
|
|
private:
|
|
struct ProxyHandler : public BaseProxyHandler
|
|
{
|
|
enum
|
|
{
|
|
EnumerateFunctionSlot = 0
|
|
};
|
|
|
|
ProxyHandler();
|
|
|
|
JS::Value getEnumerateFunction(HandleObject proxy) const;
|
|
|
|
bool getOwnPropertyDescriptor(JSContext* cx, HandleObject proxy, HandleId id,
|
|
MutableHandle<JSPropertyDescriptor> desc) const override;
|
|
bool defineProperty(JSContext* cx, HandleObject proxy, HandleId id,
|
|
Handle<JSPropertyDescriptor> desc,
|
|
ObjectOpResult& result) const override;
|
|
bool ownPropertyKeys(JSContext* cx, HandleObject proxy,
|
|
AutoIdVector& props) const override;
|
|
bool delete_(JSContext* cx, HandleObject proxy, HandleId id,
|
|
ObjectOpResult& result) const override;
|
|
bool enumerate(JSContext* cx, HandleObject proxy, MutableHandleObject objp) const override;
|
|
bool getPrototype(JSContext* cx, HandleObject proxy,
|
|
MutableHandleObject protop) const override;
|
|
bool setPrototype(JSContext* cx, HandleObject proxy, HandleObject proto,
|
|
ObjectOpResult& result) const override;
|
|
bool setImmutablePrototype(JSContext* cx, HandleObject proxy,
|
|
bool* succeeded) const override;
|
|
|
|
bool preventExtensions(JSContext* cx, HandleObject proxy,
|
|
ObjectOpResult& result) const override;
|
|
bool isExtensible(JSContext* cx, HandleObject proxy, bool* extensible) const override;
|
|
bool has(JSContext* cx, HandleObject proxy, HandleId id, bool* bp) const override;
|
|
bool get(JSContext* cx, HandleObject proxy, HandleValue receiver,
|
|
HandleId id, MutableHandleValue vp) const override;
|
|
bool set(JSContext* cx, HandleObject proxy, HandleId id, HandleValue v,
|
|
HandleValue receiver, ObjectOpResult& result) const override;
|
|
|
|
static const char family;
|
|
};
|
|
|
|
public:
|
|
static const ProxyHandler proxyHandler;
|
|
};
|
|
|
|
typedef Rooted<ModuleNamespaceObject*> RootedModuleNamespaceObject;
|
|
typedef Handle<ModuleNamespaceObject*> HandleModuleNamespaceObject;
|
|
|
|
struct FunctionDeclaration
|
|
{
|
|
FunctionDeclaration(HandleAtom name, HandleFunction fun);
|
|
void trace(JSTracer* trc);
|
|
|
|
RelocatablePtrAtom name;
|
|
RelocatablePtrFunction fun;
|
|
};
|
|
|
|
using FunctionDeclarationVector = GCVector<FunctionDeclaration, 0, ZoneAllocPolicy>;
|
|
|
|
class ModuleObject : public NativeObject
|
|
{
|
|
public:
|
|
enum
|
|
{
|
|
ScriptSlot = 0,
|
|
StaticScopeSlot,
|
|
InitialEnvironmentSlot,
|
|
EnvironmentSlot,
|
|
NamespaceSlot,
|
|
EvaluatedSlot,
|
|
RequestedModulesSlot,
|
|
ImportEntriesSlot,
|
|
LocalExportEntriesSlot,
|
|
IndirectExportEntriesSlot,
|
|
StarExportEntriesSlot,
|
|
ImportBindingsSlot,
|
|
NamespaceExportsSlot,
|
|
NamespaceBindingsSlot,
|
|
FunctionDeclarationsSlot,
|
|
SlotCount
|
|
};
|
|
|
|
static const Class class_;
|
|
|
|
static bool isInstance(HandleValue value);
|
|
|
|
static ModuleObject* create(ExclusiveContext* cx, HandleObject enclosingStaticScope);
|
|
void init(HandleScript script);
|
|
void setInitialEnvironment(Handle<ModuleEnvironmentObject*> initialEnvironment);
|
|
void initImportExportData(HandleArrayObject requestedModules,
|
|
HandleArrayObject importEntries,
|
|
HandleArrayObject localExportEntries,
|
|
HandleArrayObject indiretExportEntries,
|
|
HandleArrayObject starExportEntries);
|
|
|
|
JSScript* script() const;
|
|
JSObject* enclosingStaticScope() const;
|
|
ModuleEnvironmentObject& initialEnvironment() const;
|
|
ModuleEnvironmentObject* environment() const;
|
|
ModuleNamespaceObject* namespace_();
|
|
bool evaluated() const;
|
|
ArrayObject& requestedModules() const;
|
|
ArrayObject& importEntries() const;
|
|
ArrayObject& localExportEntries() const;
|
|
ArrayObject& indirectExportEntries() const;
|
|
ArrayObject& starExportEntries() const;
|
|
IndirectBindingMap& importBindings();
|
|
ArrayObject* namespaceExports();
|
|
IndirectBindingMap* namespaceBindings();
|
|
|
|
void createEnvironment();
|
|
|
|
bool noteFunctionDeclaration(ExclusiveContext* cx, HandleAtom name, HandleFunction fun);
|
|
static bool instantiateFunctionDeclarations(JSContext* cx, HandleModuleObject self);
|
|
|
|
void setEvaluated();
|
|
static bool evaluate(JSContext* cx, HandleModuleObject self, MutableHandleValue rval);
|
|
|
|
static ModuleNamespaceObject* createNamespace(JSContext* cx, HandleModuleObject self,
|
|
HandleArrayObject exports);
|
|
|
|
private:
|
|
static void trace(JSTracer* trc, JSObject* obj);
|
|
static void finalize(js::FreeOp* fop, JSObject* obj);
|
|
|
|
bool hasScript() const;
|
|
bool hasImportBindings() const;
|
|
FunctionDeclarationVector* functionDeclarations();
|
|
};
|
|
|
|
// Process a module's parse tree to collate the import and export data used when
|
|
// creating a ModuleObject.
|
|
class MOZ_STACK_CLASS ModuleBuilder
|
|
{
|
|
public:
|
|
explicit ModuleBuilder(JSContext* cx, HandleModuleObject module);
|
|
|
|
bool processImport(frontend::ParseNode* pn);
|
|
bool processExport(frontend::ParseNode* pn);
|
|
bool processExportFrom(frontend::ParseNode* pn);
|
|
|
|
bool hasExportedName(JSAtom* name) const;
|
|
|
|
using ExportEntryVector = GCVector<ExportEntryObject*>;
|
|
const ExportEntryVector& localExportEntries() const {
|
|
return localExportEntries_;
|
|
}
|
|
|
|
bool buildTables();
|
|
bool initModule();
|
|
|
|
private:
|
|
using AtomVector = GCVector<JSAtom*>;
|
|
using RootedAtomVector = JS::Rooted<AtomVector>;
|
|
using ImportEntryVector = GCVector<ImportEntryObject*>;
|
|
using RootedImportEntryVector = JS::Rooted<ImportEntryVector>;
|
|
using RootedExportEntryVector = JS::Rooted<ExportEntryVector>;
|
|
|
|
JSContext* cx_;
|
|
RootedModuleObject module_;
|
|
RootedAtomVector requestedModules_;
|
|
RootedAtomVector importedBoundNames_;
|
|
RootedImportEntryVector importEntries_;
|
|
RootedExportEntryVector exportEntries_;
|
|
RootedExportEntryVector localExportEntries_;
|
|
RootedExportEntryVector indirectExportEntries_;
|
|
RootedExportEntryVector starExportEntries_;
|
|
|
|
ImportEntryObject* importEntryFor(JSAtom* localName) const;
|
|
|
|
bool appendExportEntry(HandleAtom exportName, HandleAtom localName);
|
|
bool appendExportFromEntry(HandleAtom exportName, HandleAtom moduleRequest,
|
|
HandleAtom importName);
|
|
|
|
bool maybeAppendRequestedModule(HandleAtom module);
|
|
|
|
template <typename T>
|
|
ArrayObject* createArray(const GCVector<T>& vector);
|
|
};
|
|
|
|
bool InitModuleClasses(JSContext* cx, HandleObject obj);
|
|
|
|
} // namespace js
|
|
|
|
template<>
|
|
inline bool
|
|
JSObject::is<js::ModuleNamespaceObject>() const
|
|
{
|
|
return js::IsDerivedProxyObject(this, &js::ModuleNamespaceObject::proxyHandler);
|
|
}
|
|
|
|
#endif /* builtin_ModuleObject_h */
|