mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 637572 - Implement ScriptSourceObject; r=jimb
This commit is contained in:
parent
8f35d832f0
commit
a76dd02494
@ -99,6 +99,7 @@
|
||||
namespace js {
|
||||
|
||||
class Module;
|
||||
class ScriptSourceObject;
|
||||
|
||||
template <typename T>
|
||||
struct RootMethods {};
|
||||
@ -247,13 +248,14 @@ class MOZ_STACK_CLASS Handle : public js::HandleBase<T>
|
||||
void operator=(S v) MOZ_DELETE;
|
||||
};
|
||||
|
||||
typedef Handle<JSObject*> HandleObject;
|
||||
typedef Handle<js::Module*> HandleModule;
|
||||
typedef Handle<JSFunction*> HandleFunction;
|
||||
typedef Handle<JSScript*> HandleScript;
|
||||
typedef Handle<JSString*> HandleString;
|
||||
typedef Handle<jsid> HandleId;
|
||||
typedef Handle<Value> HandleValue;
|
||||
typedef Handle<JSObject*> HandleObject;
|
||||
typedef Handle<js::Module*> HandleModule;
|
||||
typedef Handle<js::ScriptSourceObject *> HandleScriptSource;
|
||||
typedef Handle<JSFunction*> HandleFunction;
|
||||
typedef Handle<JSScript*> HandleScript;
|
||||
typedef Handle<JSString*> HandleString;
|
||||
typedef Handle<jsid> HandleId;
|
||||
typedef Handle<Value> HandleValue;
|
||||
|
||||
/*
|
||||
* Similar to a handle, but the underlying storage can be changed. This is
|
||||
@ -523,13 +525,14 @@ template <>
|
||||
class Rooted<JSStableString *>;
|
||||
#endif
|
||||
|
||||
typedef Rooted<JSObject*> RootedObject;
|
||||
typedef Rooted<js::Module*> RootedModule;
|
||||
typedef Rooted<JSFunction*> RootedFunction;
|
||||
typedef Rooted<JSScript*> RootedScript;
|
||||
typedef Rooted<JSString*> RootedString;
|
||||
typedef Rooted<jsid> RootedId;
|
||||
typedef Rooted<JS::Value> RootedValue;
|
||||
typedef Rooted<JSObject*> RootedObject;
|
||||
typedef Rooted<js::Module*> RootedModule;
|
||||
typedef Rooted<js::ScriptSourceObject *> RootedScriptSource;
|
||||
typedef Rooted<JSFunction*> RootedFunction;
|
||||
typedef Rooted<JSScript*> RootedScript;
|
||||
typedef Rooted<JSString*> RootedString;
|
||||
typedef Rooted<jsid> RootedId;
|
||||
typedef Rooted<JS::Value> RootedValue;
|
||||
|
||||
} /* namespace JS */
|
||||
|
||||
|
@ -229,6 +229,7 @@ extern Class ProxyClass;
|
||||
extern Class RegExpClass;
|
||||
extern Class RegExpStaticsClass;
|
||||
extern Class SetIteratorClass;
|
||||
extern Class ScriptSourceClass;
|
||||
extern Class StopIterationClass;
|
||||
extern Class StringClass;
|
||||
extern Class StrictArgumentsObjectClass;
|
||||
@ -979,6 +980,7 @@ class JSObject : public js::ObjectImpl
|
||||
inline bool isRegExpStatics() const;
|
||||
inline bool isScope() const;
|
||||
inline bool isScript() const;
|
||||
inline bool isScriptSource() const;
|
||||
inline bool isSetIterator() const;
|
||||
inline bool isStopIteration() const;
|
||||
inline bool isTypedArray() const;
|
||||
@ -1031,6 +1033,7 @@ class JSObject : public js::ObjectImpl
|
||||
inline js::ScopeObject &asScope();
|
||||
inline js::SetObject &asSet();
|
||||
inline js::SetIteratorObject &asSetIterator();
|
||||
inline js::ScriptSourceObject &asScriptSource();
|
||||
inline js::StrictArgumentsObject &asStrictArguments();
|
||||
inline js::StaticBlockObject &asStaticBlock();
|
||||
inline js::StringObject &asString();
|
||||
|
@ -906,6 +906,7 @@ inline bool JSObject::isPrimitive() const { return isNumber() || isString() || i
|
||||
inline bool JSObject::isRegExp() const { return hasClass(&js::RegExpClass); }
|
||||
inline bool JSObject::isRegExpStatics() const { return hasClass(&js::RegExpStaticsClass); }
|
||||
inline bool JSObject::isScope() const { return isCall() || isDeclEnv() || isNestedScope(); }
|
||||
inline bool JSObject::isScriptSource() const { return hasClass(&js::ScriptSourceClass); }
|
||||
inline bool JSObject::isSetIterator() const { return hasClass(&js::SetIteratorClass); }
|
||||
inline bool JSObject::isStaticBlock() const { return isBlock() && !getProto(); }
|
||||
inline bool JSObject::isStopIteration() const { return hasClass(&js::StopIterationClass); }
|
||||
|
@ -893,6 +893,38 @@ JSScript::destroyScriptCounts(FreeOp *fop)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ScriptSourceObject::finalize(FreeOp *fop, JSObject *obj)
|
||||
{
|
||||
// ScriptSource::setSource automatically takes care of the refcount
|
||||
obj->asScriptSource().setSource(NULL);
|
||||
}
|
||||
|
||||
Class js::ScriptSourceClass = {
|
||||
"ScriptSource",
|
||||
JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_IS_ANONYMOUS,
|
||||
JS_PropertyStub, /* addProperty */
|
||||
JS_DeletePropertyStub, /* delProperty */
|
||||
JS_PropertyStub, /* getProperty */
|
||||
JS_StrictPropertyStub, /* setProperty */
|
||||
JS_EnumerateStub,
|
||||
JS_ResolveStub,
|
||||
JS_ConvertStub,
|
||||
ScriptSourceObject::finalize
|
||||
};
|
||||
|
||||
ScriptSourceObject *
|
||||
ScriptSourceObject::create(JSContext *cx, ScriptSource *source)
|
||||
{
|
||||
RootedObject object(cx, NewObjectWithGivenProto(cx, &ScriptSourceClass, NULL, cx->global()));
|
||||
if (!object)
|
||||
return NULL;
|
||||
JS::RootedScriptSource sourceObject(cx, &object->asScriptSource());
|
||||
sourceObject->setSlot(SOURCE_SLOT, PrivateValue(source));
|
||||
source->incref();
|
||||
return sourceObject;
|
||||
}
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
void
|
||||
SourceCompressorThread::compressorThread(void *arg)
|
||||
|
@ -1079,6 +1079,27 @@ class ScriptSourceHolder
|
||||
}
|
||||
};
|
||||
|
||||
class ScriptSourceObject : public JSObject {
|
||||
public:
|
||||
static void finalize(FreeOp *fop, JSObject *obj);
|
||||
static ScriptSourceObject *create(JSContext *cx, ScriptSource *source);
|
||||
|
||||
ScriptSource *source() {
|
||||
return static_cast<ScriptSource *>(getReservedSlot(SOURCE_SLOT).toPrivate());
|
||||
}
|
||||
|
||||
void setSource(ScriptSource *source) {
|
||||
if (source)
|
||||
source->incref();
|
||||
if (this->source())
|
||||
this->source()->decref();
|
||||
setReservedSlot(SOURCE_SLOT, PrivateValue(source));
|
||||
}
|
||||
|
||||
private:
|
||||
static const uint32_t SOURCE_SLOT = 0;
|
||||
};
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
/*
|
||||
* Background thread to compress JS source code. This happens only while parsing
|
||||
@ -1250,6 +1271,13 @@ struct ScriptAndCounts
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
inline js::ScriptSourceObject &
|
||||
JSObject::asScriptSource()
|
||||
{
|
||||
JS_ASSERT(isScriptSource());
|
||||
return *static_cast<js::ScriptSourceObject *>(this);
|
||||
}
|
||||
|
||||
extern jssrcnote *
|
||||
js_GetSrcNote(JSContext *cx, JSScript *script, jsbytecode *pc);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user