Attachment #687721: Module objects for bug #568953

View | Details | Raw Unified | Return to bug 568953
Collapse All | Expand All

(-)a/js/src/Makefile.in (+1 lines)
Line     Link Here 
 Lines 148-163   CPPSRCS = \ Link Here 
148
		Statistics.cpp \
148
		Statistics.cpp \
149
		StoreBuffer.cpp \
149
		StoreBuffer.cpp \
150
		FindSCCs.cpp \
150
		FindSCCs.cpp \
151
		Iteration.cpp \
151
		Iteration.cpp \
152
		Verifier.cpp \
152
		Verifier.cpp \
153
		StringBuffer.cpp \
153
		StringBuffer.cpp \
154
		Unicode.cpp \
154
		Unicode.cpp \
155
		Xdr.cpp \
155
		Xdr.cpp \
156
		Module.cpp \
156
		$(NULL)
157
		$(NULL)
157
158
158
# Changes to internal header files, used externally, massively slow down
159
# Changes to internal header files, used externally, massively slow down
159
# browser builds.  Don't add new files here unless you know what you're
160
# browser builds.  Don't add new files here unless you know what you're
160
# doing!
161
# doing!
161
INSTALLED_HEADERS = \
162
INSTALLED_HEADERS = \
162
		js-config.h \
163
		js-config.h \
163
		jscpucfg.h \
164
		jscpucfg.h \
(-)827260eb78e5 (+40 lines)
Added Link Here 
Added Link Here 
1
#include "jsobjinlines.h"
2
#include "builtin/Module.h"
3
#include "gc/Marking.h"
4
5
using namespace js;
6
7
Class js::ModuleClass = {
8
    js_Module_str,
9
    JSCLASS_HAS_RESERVED_SLOTS(2),
10
    JS_PropertyStub,        /* addProperty */
11
    JS_PropertyStub,        /* delProperty */
12
    JS_PropertyStub,        /* getProperty */
13
    JS_StrictPropertyStub,  /* setProperty */
14
    JS_EnumerateStub,
15
    JS_ResolveStub,
16
    JS_ConvertStub
17
};
18
19
JSObject *
20
js_InitModuleClass(JSContext *cx, HandleObject obj)
21
{
22
    Rooted<GlobalObject *> global(cx, &obj->asGlobal());
23
    return global->createBlankPrototype(cx, &ModuleClass);
24
}
25
26
Module *
27
js_NewModule(JSContext *cx, JSAtom *atom)
28
{
29
    RootedModule module(cx, &NewBuiltinClassInstance(cx, &ModuleClass)->asModule());
30
    module->setAtom(atom);
31
    module->setScript(NULL);
32
    return module;
33
}
34
35
Module &
36
JSObject::asModule()
37
{
38
    JS_ASSERT(isModule());
39
    return *static_cast<Module *>(this);
40
}
(-)827260eb78e5 (+39 lines)
Added Link Here 
Added Link Here 
1
#ifndef Module_h___
2
#define Module_h___
3
4
#include "jsobj.h"
5
6
namespace js {
7
8
class Module : public JSObject {
9
  public:
10
    JSAtom *atom() {
11
        return (JSAtom *) GetReservedSlot(this, ATOM_SLOT).toPrivate();
12
    };
13
14
    void setAtom(JSAtom *atom) {
15
        SetReservedSlot(this, ATOM_SLOT, PrivateValue(atom));
16
    };
17
18
    JSScript *script() {
19
        return (JSScript *) GetReservedSlot(this, SCRIPT_SLOT).toPrivate();
20
    }
21
22
    void setScript(JSScript *script) {
23
        SetReservedSlot(this, SCRIPT_SLOT, PrivateValue(script));
24
    }
25
26
  private:
27
    static const uint32_t ATOM_SLOT = 0;
28
    static const uint32_t SCRIPT_SLOT = 1;
29
};
30
31
} // namespace js
32
33
JSObject *
34
js_InitModuleClass(JSContext *cx, js::HandleObject obj);
35
36
js::Module *
37
js_NewModule(JSContext *cx, JSAtom *atom);
38
39
#endif // Module_h___
(-)a/js/src/gc/Root.h (+4 lines)
Line     Link Here 
 Lines 57-72    Link Here 
57
 *   then redundant rooting of multiple copies of the GC thing can be avoided.
57
 *   then redundant rooting of multiple copies of the GC thing can be avoided.
58
 *   Second, if the caller does not pass a rooted value a compile error will be
58
 *   Second, if the caller does not pass a rooted value a compile error will be
59
 *   generated, which is quicker and easier to fix than when relying on a
59
 *   generated, which is quicker and easier to fix than when relying on a
60
 *   separate rooting analysis.
60
 *   separate rooting analysis.
61
 */
61
 */
62
62
63
namespace js {
63
namespace js {
64
64
65
class Module;
66
65
template <typename T> class Rooted;
67
template <typename T> class Rooted;
66
68
67
template <typename T>
69
template <typename T>
68
struct RootMethods {};
70
struct RootMethods {};
69
71
70
template <typename T>
72
template <typename T>
71
class HandleBase {};
73
class HandleBase {};
72
74
 Lines 173-188   class Handle : public js::HandleBase<T> Link Here 
173
175
174
    const T *ptr;
176
    const T *ptr;
175
177
176
    template <typename S>
178
    template <typename S>
177
    void operator =(S v) MOZ_DELETE;
179
    void operator =(S v) MOZ_DELETE;
178
};
180
};
179
181
180
typedef Handle<JSObject*>    HandleObject;
182
typedef Handle<JSObject*>    HandleObject;
183
typedef Handle<js::Module*>  HandleModule;
181
typedef Handle<JSFunction*>  HandleFunction;
184
typedef Handle<JSFunction*>  HandleFunction;
182
typedef Handle<JSScript*>    HandleScript;
185
typedef Handle<JSScript*>    HandleScript;
183
typedef Handle<JSString*>    HandleString;
186
typedef Handle<JSString*>    HandleString;
184
typedef Handle<jsid>         HandleId;
187
typedef Handle<jsid>         HandleId;
185
typedef Handle<Value>        HandleValue;
188
typedef Handle<Value>        HandleValue;
186
189
187
/*
190
/*
188
 * Similar to a handle, but the underlying storage can be changed. This is
191
 * Similar to a handle, but the underlying storage can be changed. This is
 Lines 699-714   class Rooted<JSStableString *>; Link Here 
699
template <typename T>
702
template <typename T>
700
bool
703
bool
701
Return<T>::operator==(const Rooted<T> &other)
704
Return<T>::operator==(const Rooted<T> &other)
702
{
705
{
703
    return ptr_ == other.get();
706
    return ptr_ == other.get();
704
}
707
}
705
708
706
typedef Rooted<JSObject*>    RootedObject;
709
typedef Rooted<JSObject*>    RootedObject;
710
typedef Rooted<js::Module*>  RootedModule;
707
typedef Rooted<JSFunction*>  RootedFunction;
711
typedef Rooted<JSFunction*>  RootedFunction;
708
typedef Rooted<JSScript*>    RootedScript;
712
typedef Rooted<JSScript*>    RootedScript;
709
typedef Rooted<JSString*>    RootedString;
713
typedef Rooted<JSString*>    RootedString;
710
typedef Rooted<jsid>         RootedId;
714
typedef Rooted<jsid>         RootedId;
711
typedef Rooted<Value>        RootedValue;
715
typedef Rooted<Value>        RootedValue;
712
716
713
/*
717
/*
714
 * Mark a stack location as a root for the rooting analysis, without actually
718
 * Mark a stack location as a root for the rooting analysis, without actually
(-)a/js/src/jsobj.cpp (+1 lines)
Line     Link Here 
 Lines 41-56    Link Here 
41
#include "jsstr.h"
41
#include "jsstr.h"
42
#include "jsdbgapi.h"
42
#include "jsdbgapi.h"
43
#include "json.h"
43
#include "json.h"
44
#include "jswatchpoint.h"
44
#include "jswatchpoint.h"
45
#include "jswrapper.h"
45
#include "jswrapper.h"
46
#include "jsxml.h"
46
#include "jsxml.h"
47
47
48
#include "builtin/MapObject.h"
48
#include "builtin/MapObject.h"
49
#include "builtin/Module.h"
49
#include "builtin/ParallelArray.h"
50
#include "builtin/ParallelArray.h"
50
#include "frontend/BytecodeCompiler.h"
51
#include "frontend/BytecodeCompiler.h"
51
#include "frontend/Parser.h"
52
#include "frontend/Parser.h"
52
#include "gc/Marking.h"
53
#include "gc/Marking.h"
53
#include "js/MemoryMetrics.h"
54
#include "js/MemoryMetrics.h"
54
#include "vm/StringBuffer.h"
55
#include "vm/StringBuffer.h"
55
#include "vm/Xdr.h"
56
#include "vm/Xdr.h"
56
57
(-)a/js/src/jsobj.h (+4 lines)
Line     Link Here 
 Lines 207-222   extern Class DataViewClass; Link Here 
207
extern Class DateClass;
207
extern Class DateClass;
208
extern Class ErrorClass;
208
extern Class ErrorClass;
209
extern Class ElementIteratorClass;
209
extern Class ElementIteratorClass;
210
extern Class GeneratorClass;
210
extern Class GeneratorClass;
211
extern Class IntlClass;
211
extern Class IntlClass;
212
extern Class JSONClass;
212
extern Class JSONClass;
213
extern Class MapIteratorClass;
213
extern Class MapIteratorClass;
214
extern Class MathClass;
214
extern Class MathClass;
215
extern Class ModuleClass;
215
extern Class NumberClass;
216
extern Class NumberClass;
216
extern Class NormalArgumentsObjectClass;
217
extern Class NormalArgumentsObjectClass;
217
extern Class ObjectClass;
218
extern Class ObjectClass;
218
extern Class ProxyClass;
219
extern Class ProxyClass;
219
extern Class RegExpClass;
220
extern Class RegExpClass;
220
extern Class RegExpStaticsClass;
221
extern Class RegExpStaticsClass;
221
extern Class SetIteratorClass;
222
extern Class SetIteratorClass;
222
extern Class SlowArrayClass;
223
extern Class SlowArrayClass;
 Lines 234-249   class BooleanObject; Link Here 
234
class ClonedBlockObject;
235
class ClonedBlockObject;
235
class DataViewObject;
236
class DataViewObject;
236
class DebugScopeObject;
237
class DebugScopeObject;
237
class DeclEnvObject;
238
class DeclEnvObject;
238
class ElementIteratorObject;
239
class ElementIteratorObject;
239
class GlobalObject;
240
class GlobalObject;
240
class MapObject;
241
class MapObject;
241
class MapIteratorObject;
242
class MapIteratorObject;
243
class Module;
242
class NestedScopeObject;
244
class NestedScopeObject;
243
class NewObjectCache;
245
class NewObjectCache;
244
class NormalArgumentsObject;
246
class NormalArgumentsObject;
245
class NumberObject;
247
class NumberObject;
246
class PropertyIteratorObject;
248
class PropertyIteratorObject;
247
class ScopeObject;
249
class ScopeObject;
248
class SetObject;
250
class SetObject;
249
class SetIteratorObject;
251
class SetIteratorObject;
 Lines 957-972   struct JSObject : public js::ObjectImpl Link Here 
957
    inline bool isDataView() const;
959
    inline bool isDataView() const;
958
    inline bool isDate() const;
960
    inline bool isDate() const;
959
    inline bool isElementIterator() const;
961
    inline bool isElementIterator() const;
960
    inline bool isError() const;
962
    inline bool isError() const;
961
    inline bool isFunction() const;
963
    inline bool isFunction() const;
962
    inline bool isGenerator() const;
964
    inline bool isGenerator() const;
963
    inline bool isGlobal() const;
965
    inline bool isGlobal() const;
964
    inline bool isMapIterator() const;
966
    inline bool isMapIterator() const;
967
    inline bool isModule() const;
965
    inline bool isObject() const;
968
    inline bool isObject() const;
966
    inline bool isPrimitive() const;
969
    inline bool isPrimitive() const;
967
    inline bool isPropertyIterator() const;
970
    inline bool isPropertyIterator() const;
968
    inline bool isProxy() const;
971
    inline bool isProxy() const;
969
    inline bool isRegExp() const;
972
    inline bool isRegExp() const;
970
    inline bool isRegExpStatics() const;
973
    inline bool isRegExpStatics() const;
971
    inline bool isScope() const;
974
    inline bool isScope() const;
972
    inline bool isScript() const;
975
    inline bool isScript() const;
 Lines 1013-1028   struct JSObject : public js::ObjectImpl Link Here 
1013
    inline js::CallObject &asCall();
1016
    inline js::CallObject &asCall();
1014
    inline js::ClonedBlockObject &asClonedBlock();
1017
    inline js::ClonedBlockObject &asClonedBlock();
1015
    inline js::DataViewObject &asDataView();
1018
    inline js::DataViewObject &asDataView();
1016
    inline js::DeclEnvObject &asDeclEnv();
1019
    inline js::DeclEnvObject &asDeclEnv();
1017
    inline js::DebugScopeObject &asDebugScope();
1020
    inline js::DebugScopeObject &asDebugScope();
1018
    inline js::GlobalObject &asGlobal();
1021
    inline js::GlobalObject &asGlobal();
1019
    inline js::MapObject &asMap();
1022
    inline js::MapObject &asMap();
1020
    inline js::MapIteratorObject &asMapIterator();
1023
    inline js::MapIteratorObject &asMapIterator();
1024
    inline js::Module &asModule();
1021
    inline js::NestedScopeObject &asNestedScope();
1025
    inline js::NestedScopeObject &asNestedScope();
1022
    inline js::NormalArgumentsObject &asNormalArguments();
1026
    inline js::NormalArgumentsObject &asNormalArguments();
1023
    inline js::NumberObject &asNumber();
1027
    inline js::NumberObject &asNumber();
1024
    inline js::PropertyIteratorObject &asPropertyIterator();
1028
    inline js::PropertyIteratorObject &asPropertyIterator();
1025
    inline const js::PropertyIteratorObject &asPropertyIterator() const;
1029
    inline const js::PropertyIteratorObject &asPropertyIterator() const;
1026
    inline js::RegExpObject &asRegExp();
1030
    inline js::RegExpObject &asRegExp();
1027
    inline js::ScopeObject &asScope();
1031
    inline js::ScopeObject &asScope();
1028
    inline js::SetObject &asSet();
1032
    inline js::SetObject &asSet();
(-)a/js/src/jsobjinlines.h (+1 lines)
Line     Link Here 
 Lines 790-805   inline bool JSObject::isDataView() const Link Here 
790
inline bool JSObject::isDate() const { return hasClass(&js::DateClass); }
790
inline bool JSObject::isDate() const { return hasClass(&js::DateClass); }
791
inline bool JSObject::isDeclEnv() const { return hasClass(&js::DeclEnvClass); }
791
inline bool JSObject::isDeclEnv() const { return hasClass(&js::DeclEnvClass); }
792
inline bool JSObject::isElementIterator() const { return hasClass(&js::ElementIteratorClass); }
792
inline bool JSObject::isElementIterator() const { return hasClass(&js::ElementIteratorClass); }
793
inline bool JSObject::isError() const { return hasClass(&js::ErrorClass); }
793
inline bool JSObject::isError() const { return hasClass(&js::ErrorClass); }
794
inline bool JSObject::isFunction() const { return hasClass(&js::FunctionClass); }
794
inline bool JSObject::isFunction() const { return hasClass(&js::FunctionClass); }
795
inline bool JSObject::isFunctionProxy() const { return hasClass(&js::FunctionProxyClass); }
795
inline bool JSObject::isFunctionProxy() const { return hasClass(&js::FunctionProxyClass); }
796
inline bool JSObject::isGenerator() const { return hasClass(&js::GeneratorClass); }
796
inline bool JSObject::isGenerator() const { return hasClass(&js::GeneratorClass); }
797
inline bool JSObject::isMapIterator() const { return hasClass(&js::MapIteratorClass); }
797
inline bool JSObject::isMapIterator() const { return hasClass(&js::MapIteratorClass); }
798
inline bool JSObject::isModule() const { return hasClass(&js::ModuleClass); }
798
inline bool JSObject::isNestedScope() const { return isBlock() || isWith(); }
799
inline bool JSObject::isNestedScope() const { return isBlock() || isWith(); }
799
inline bool JSObject::isNormalArguments() const { return hasClass(&js::NormalArgumentsObjectClass); }
800
inline bool JSObject::isNormalArguments() const { return hasClass(&js::NormalArgumentsObjectClass); }
800
inline bool JSObject::isNumber() const { return hasClass(&js::NumberClass); }
801
inline bool JSObject::isNumber() const { return hasClass(&js::NumberClass); }
801
inline bool JSObject::isObject() const { return hasClass(&js::ObjectClass); }
802
inline bool JSObject::isObject() const { return hasClass(&js::ObjectClass); }
802
inline bool JSObject::isPrimitive() const { return isNumber() || isString() || isBoolean(); }
803
inline bool JSObject::isPrimitive() const { return isNumber() || isString() || isBoolean(); }
803
inline bool JSObject::isRegExp() const { return hasClass(&js::RegExpClass); }
804
inline bool JSObject::isRegExp() const { return hasClass(&js::RegExpClass); }
804
inline bool JSObject::isRegExpStatics() const { return hasClass(&js::RegExpStaticsClass); }
805
inline bool JSObject::isRegExpStatics() const { return hasClass(&js::RegExpStaticsClass); }
805
inline bool JSObject::isScope() const { return isCall() || isDeclEnv() || isNestedScope(); }
806
inline bool JSObject::isScope() const { return isCall() || isDeclEnv() || isNestedScope(); }
(-)a/js/src/jsprototypes.h (+1 lines)
Line     Link Here 
 Lines 56-65    Link Here 
56
    macro(Proxy,                 34,     js_InitProxyClass) \
56
    macro(Proxy,                 34,     js_InitProxyClass) \
57
    macro(AnyName,               35,     js_InitNullClass) \
57
    macro(AnyName,               35,     js_InitNullClass) \
58
    macro(WeakMap,               36,     js_InitWeakMapClass) \
58
    macro(WeakMap,               36,     js_InitWeakMapClass) \
59
    macro(Map,                   37,     js_InitMapClass) \
59
    macro(Map,                   37,     js_InitMapClass) \
60
    macro(Set,                   38,     js_InitSetClass) \
60
    macro(Set,                   38,     js_InitSetClass) \
61
    macro(DataView,              39,     js_InitTypedArrayClasses) \
61
    macro(DataView,              39,     js_InitTypedArrayClasses) \
62
    macro(ParallelArray,         40,     js_InitParallelArrayClass) \
62
    macro(ParallelArray,         40,     js_InitParallelArrayClass) \
63
    macro(Intl,                  41,     js_InitIntlClass) \
63
    macro(Intl,                  41,     js_InitIntlClass) \
64
    macro(Module,                42,     js_InitModuleClass) \
64
65
65
#endif /* jsprototypes_h___ */
66
#endif /* jsprototypes_h___ */

Return to bug 568953