summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/script/value_wrapper_synthetic_module_script.h
blob: ae19c095cd9b4ee9ba8707ccc3c8e19c05fd2e1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2019 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 THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_VALUE_WRAPPER_SYNTHETIC_MODULE_SCRIPT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_VALUE_WRAPPER_SYNTHETIC_MODULE_SCRIPT_H_

#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/script/module_script.h"

namespace WTF {
class TextPosition;
}  // namespace WTF

namespace blink {

class KURL;
class Modulator;
class ModuleScriptCreationParams;

// ValueWrapperSyntheticModuleScript is a module script
// (https://html.spec.whatwg.org/C/#module-script) that default-exports a single
// v8::Value, for example JSON Module Script:
// https://html.spec.whatwg.org/multipage/webappapis.html#json-module-script
class CORE_EXPORT ValueWrapperSyntheticModuleScript final
    : public ModuleScript {
 public:
  static ValueWrapperSyntheticModuleScript*
  CreateJSONWrapperSyntheticModuleScript(
      const base::Optional<ModuleScriptCreationParams>& params,
      Modulator* settings_object,
      const ScriptFetchOptions options_);

  static ValueWrapperSyntheticModuleScript* CreateWithDefaultExport(
      v8::Local<v8::Value> value,
      Modulator* settings_object,
      const KURL& source_url,
      const KURL& base_url,
      const ScriptFetchOptions& fetch_options,
      const TextPosition& start_position = TextPosition::MinimumPosition());

  static ValueWrapperSyntheticModuleScript* CreateWithError(
      v8::Local<v8::Value> value,
      Modulator* settings_object,
      const KURL& source_url,
      const KURL& base_url,
      const ScriptFetchOptions& fetch_options,
      v8::Local<v8::Value> error,
      const TextPosition& start_position = TextPosition::MinimumPosition());

  ValueWrapperSyntheticModuleScript(Modulator* settings_object,
                                    ModuleRecord record,
                                    const KURL& source_url,
                                    const KURL& base_url,
                                    const ScriptFetchOptions& fetch_options,
                                    v8::Local<v8::Value> value,
                                    const TextPosition& start_position);

  // <specdef
  // href="https://heycam.github.io/webidl/#synthetic-module-record">
  // An abstract operation that will be performed upon evaluation of the module,
  // taking the Synthetic Module Record as its sole argument. These will usually
  // set up the exported values, by using SetSyntheticModuleExport. They must
  // not modify [[ExportNames]]. They may return an abrupt completion.
  static v8::MaybeLocal<v8::Value> EvaluationSteps(
      v8::Local<v8::Context> context,
      v8::Local<v8::Module> module);

  String InlineSourceTextForCSP() const override;
  void Trace(blink::Visitor* visitor) override;

 private:
  TraceWrapperV8Reference<v8::Value> export_value_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_CORE_SCRIPT_VALUE_WRAPPER_SYNTHETIC_MODULE_SCRIPT_H_