2017-05-08 09:24:44 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2018-12-07 00:52:15 +03:00
|
|
|
#ifndef mozilla_dom_LoadedScript_h
|
|
|
|
#define mozilla_dom_LoadedScript_h
|
2017-05-08 09:24:44 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "jsapi.h"
|
2018-12-07 00:52:15 +03:00
|
|
|
#include "ScriptLoadRequest.h"
|
2017-05-08 09:24:44 +03:00
|
|
|
|
|
|
|
class nsIURI;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class ScriptLoader;
|
|
|
|
|
2019-01-18 16:37:43 +03:00
|
|
|
void HostAddRefTopLevelScript(const JS::Value& aPrivate);
|
|
|
|
void HostReleaseTopLevelScript(const JS::Value& aPrivate);
|
2018-12-07 00:52:15 +03:00
|
|
|
|
2018-12-07 00:52:15 +03:00
|
|
|
class ClassicScript;
|
|
|
|
class ModuleScript;
|
2020-05-12 22:28:15 +03:00
|
|
|
class EventScript;
|
2018-12-07 00:52:15 +03:00
|
|
|
|
|
|
|
class LoadedScript : public nsISupports {
|
|
|
|
ScriptKind mKind;
|
2018-12-07 00:52:15 +03:00
|
|
|
RefPtr<ScriptFetchOptions> mFetchOptions;
|
2017-05-08 09:24:44 +03:00
|
|
|
nsCOMPtr<nsIURI> mBaseURL;
|
2018-12-07 00:52:15 +03:00
|
|
|
|
|
|
|
protected:
|
2018-12-07 00:52:18 +03:00
|
|
|
LoadedScript(ScriptKind aKind, ScriptFetchOptions* aFetchOptions,
|
|
|
|
nsIURI* aBaseURL);
|
2018-12-07 00:52:15 +03:00
|
|
|
|
|
|
|
virtual ~LoadedScript();
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(LoadedScript)
|
|
|
|
|
|
|
|
bool IsModuleScript() const { return mKind == ScriptKind::eModule; }
|
2020-05-12 22:28:15 +03:00
|
|
|
bool IsEventScript() const { return mKind == ScriptKind::eEvent; }
|
2018-12-07 00:52:15 +03:00
|
|
|
|
|
|
|
inline ClassicScript* AsClassicScript();
|
|
|
|
inline ModuleScript* AsModuleScript();
|
2020-05-12 22:28:15 +03:00
|
|
|
inline EventScript* AsEventScript();
|
2018-12-07 00:52:15 +03:00
|
|
|
|
2020-05-12 22:28:15 +03:00
|
|
|
ScriptFetchOptions* GetFetchOptions() const { return mFetchOptions; }
|
2018-12-07 00:52:15 +03:00
|
|
|
nsIURI* BaseURL() const { return mBaseURL; }
|
2018-12-07 00:52:17 +03:00
|
|
|
|
|
|
|
void AssociateWithScript(JSScript* aScript);
|
2018-12-07 00:52:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ClassicScript final : public LoadedScript {
|
|
|
|
~ClassicScript() = default;
|
|
|
|
|
|
|
|
public:
|
2018-12-07 00:52:18 +03:00
|
|
|
ClassicScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL);
|
2018-12-07 00:52:15 +03:00
|
|
|
};
|
|
|
|
|
2020-05-12 22:28:15 +03:00
|
|
|
class EventScript final : public LoadedScript {
|
|
|
|
~EventScript() = default;
|
|
|
|
|
|
|
|
public:
|
|
|
|
EventScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL);
|
|
|
|
};
|
|
|
|
|
2018-12-07 00:52:15 +03:00
|
|
|
// A single module script. May be used to satisfy multiple load requests.
|
|
|
|
|
|
|
|
class ModuleScript final : public LoadedScript {
|
2018-10-04 13:50:55 +03:00
|
|
|
JS::Heap<JSObject*> mModuleRecord;
|
2017-12-06 17:54:58 +03:00
|
|
|
JS::Heap<JS::Value> mParseError;
|
|
|
|
JS::Heap<JS::Value> mErrorToRethrow;
|
2019-02-01 13:26:14 +03:00
|
|
|
bool mDebuggerDataInitialized;
|
2017-05-08 09:24:44 +03:00
|
|
|
|
|
|
|
~ModuleScript();
|
|
|
|
|
|
|
|
public:
|
2018-12-07 00:52:15 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ModuleScript,
|
|
|
|
LoadedScript)
|
2017-05-08 09:24:44 +03:00
|
|
|
|
2018-12-07 00:52:18 +03:00
|
|
|
ModuleScript(ScriptFetchOptions* aFetchOptions, nsIURI* aBaseURL);
|
2017-08-22 12:34:14 +03:00
|
|
|
|
2018-10-04 13:50:55 +03:00
|
|
|
void SetModuleRecord(JS::Handle<JSObject*> aModuleRecord);
|
2017-12-06 17:54:58 +03:00
|
|
|
void SetParseError(const JS::Value& aError);
|
|
|
|
void SetErrorToRethrow(const JS::Value& aError);
|
2019-02-01 13:26:14 +03:00
|
|
|
void SetDebuggerDataInitialized();
|
2017-05-08 09:24:44 +03:00
|
|
|
|
2018-10-04 13:50:55 +03:00
|
|
|
JSObject* ModuleRecord() const { return mModuleRecord; }
|
2018-12-07 00:52:15 +03:00
|
|
|
|
2017-12-06 17:54:58 +03:00
|
|
|
JS::Value ParseError() const { return mParseError; }
|
|
|
|
JS::Value ErrorToRethrow() const { return mErrorToRethrow; }
|
|
|
|
bool HasParseError() const { return !mParseError.isUndefined(); }
|
|
|
|
bool HasErrorToRethrow() const { return !mErrorToRethrow.isUndefined(); }
|
2019-02-01 13:26:14 +03:00
|
|
|
bool DebuggerDataInitialized() const { return mDebuggerDataInitialized; }
|
2017-08-22 12:34:14 +03:00
|
|
|
|
2018-10-04 13:50:55 +03:00
|
|
|
void UnlinkModuleRecord();
|
2018-12-07 00:52:15 +03:00
|
|
|
|
2019-01-18 16:37:43 +03:00
|
|
|
friend void CheckModuleScriptPrivate(LoadedScript*, const JS::Value&);
|
2017-05-08 09:24:44 +03:00
|
|
|
};
|
|
|
|
|
2018-12-07 00:52:15 +03:00
|
|
|
ClassicScript* LoadedScript::AsClassicScript() {
|
|
|
|
MOZ_ASSERT(!IsModuleScript());
|
|
|
|
return static_cast<ClassicScript*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ModuleScript* LoadedScript::AsModuleScript() {
|
|
|
|
MOZ_ASSERT(IsModuleScript());
|
|
|
|
return static_cast<ModuleScript*>(this);
|
|
|
|
}
|
|
|
|
|
2017-05-08 09:24:44 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-12-07 00:52:15 +03:00
|
|
|
#endif // mozilla_dom_LoadedScript_h
|