blob: 3f0481e799ad2980692db7fb651abe367197f4b4 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ModuleScript_h
#define ModuleScript_h
#include "bindings/core/v8/ScriptModule.h"
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/TraceWrapperV8Reference.h"
#include "core/CoreExport.h"
#include "platform/heap/Handle.h"
#include "platform/loader/fetch/ResourceLoaderOptions.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/WebURLRequest.h"
namespace blink {
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-instantiation-state
enum class ModuleInstantiationState {
Uninstantiated,
Errored,
Instantiated,
};
// ModuleScript is a model object for the "module script" spec concept.
// https://html.spec.whatwg.org/multipage/webappapis.html#module-script
class CORE_EXPORT ModuleScript final
: public GarbageCollectedFinalized<ModuleScript>,
public TraceWrapperBase {
public:
static ModuleScript* create(
ScriptModule record,
const KURL& baseURL,
const String& nonce,
ParserDisposition parserState,
WebURLRequest::FetchCredentialsMode credentialsMode) {
return new ModuleScript(record, baseURL, nonce, parserState,
credentialsMode);
}
~ModuleScript() = default;
ScriptModule& record() { return m_record; }
void clearRecord() { m_record = ScriptModule(); }
const KURL& baseURL() const { return m_baseURL; }
ModuleInstantiationState instantiationState() const {
return m_instantiationState;
}
void setInstantiationSuccess();
void setInstantiationError(v8::Isolate*, v8::Local<v8::Value> error);
ParserDisposition parserState() const { return m_parserState; }
WebURLRequest::FetchCredentialsMode credentialsMode() const {
return m_credentialsMode;
}
const String& nonce() const { return m_nonce; }
DECLARE_TRACE();
DECLARE_VIRTUAL_TRACE_WRAPPERS();
private:
ModuleScript(ScriptModule record,
const KURL& baseURL,
const String& nonce,
ParserDisposition parserState,
WebURLRequest::FetchCredentialsMode credentialsMode)
: m_record(record),
m_baseURL(baseURL),
m_instantiationError(this),
m_nonce(nonce),
m_parserState(parserState),
m_credentialsMode(credentialsMode) {}
// Note: A "module script"'s "setttings object" is ommitted, as we currently
// always have access to the corresponding Modulator when operating on a
// ModuleScript instance.
// https://html.spec.whatwg.org/multipage/webappapis.html#settings-object
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-module-record
ScriptModule m_record;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-base-url
const KURL m_baseURL;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-instantiation-state
ModuleInstantiationState m_instantiationState =
ModuleInstantiationState::Uninstantiated;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-instantiation-error
TraceWrapperV8Reference<v8::Value> m_instantiationError;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-nonce
const String m_nonce;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-parser
const ParserDisposition m_parserState;
// https://html.spec.whatwg.org/multipage/webappapis.html#concept-module-script-credentials-mode
const WebURLRequest::FetchCredentialsMode m_credentialsMode;
};
} // namespace blink
#endif