• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef INCLUDE_V8_SCRIPT_H_
6 #define INCLUDE_V8_SCRIPT_H_
7 
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include <memory>
12 #include <vector>
13 
14 #include "v8-data.h"          // NOLINT(build/include_directory)
15 #include "v8-local-handle.h"  // NOLINT(build/include_directory)
16 #include "v8-maybe.h"         // NOLINT(build/include_directory)
17 #include "v8-message.h"       // NOLINT(build/include_directory)
18 #include "v8config.h"         // NOLINT(build/include_directory)
19 
20 namespace v8 {
21 
22 class Function;
23 class Object;
24 class PrimitiveArray;
25 class Script;
26 
27 namespace internal {
28 class BackgroundDeserializeTask;
29 struct ScriptStreamingData;
30 }  // namespace internal
31 
32 /**
33  * A container type that holds relevant metadata for module loading.
34  *
35  * This is passed back to the embedder as part of
36  * HostImportModuleDynamicallyCallback for module loading.
37  */
38 class V8_EXPORT ScriptOrModule {
39  public:
40   /**
41    * The name that was passed by the embedder as ResourceName to the
42    * ScriptOrigin. This can be either a v8::String or v8::Undefined.
43    */
44   Local<Value> GetResourceName();
45 
46   /**
47    * The options that were passed by the embedder as HostDefinedOptions to
48    * the ScriptOrigin.
49    */
50   V8_DEPRECATED("Use HostDefinedOptions")
51   Local<PrimitiveArray> GetHostDefinedOptions();
52   Local<Data> HostDefinedOptions();
53 };
54 
55 /**
56  * A compiled JavaScript script, not yet tied to a Context.
57  */
58 class V8_EXPORT UnboundScript {
59  public:
60   /**
61    * Binds the script to the currently entered context.
62    */
63   Local<Script> BindToCurrentContext();
64 
65   int GetId() const;
66   Local<Value> GetScriptName();
67 
68   /**
69    * Data read from magic sourceURL comments.
70    */
71   Local<Value> GetSourceURL();
72   /**
73    * Data read from magic sourceMappingURL comments.
74    */
75   Local<Value> GetSourceMappingURL();
76 
77   /**
78    * Returns zero based line number of the code_pos location in the script.
79    * -1 will be returned if no information available.
80    */
81   int GetLineNumber(int code_pos);
82 
83   static const int kNoScriptId = 0;
84 };
85 
86 /**
87  * A compiled JavaScript module, not yet tied to a Context.
88  */
89 class V8_EXPORT UnboundModuleScript : public Data {
90   // Only used as a container for code caching.
91 };
92 
93 /**
94  * A location in JavaScript source.
95  */
96 class V8_EXPORT Location {
97  public:
GetLineNumber()98   int GetLineNumber() { return line_number_; }
GetColumnNumber()99   int GetColumnNumber() { return column_number_; }
100 
Location(int line_number,int column_number)101   Location(int line_number, int column_number)
102       : line_number_(line_number), column_number_(column_number) {}
103 
104  private:
105   int line_number_;
106   int column_number_;
107 };
108 
109 class V8_EXPORT ModuleRequest : public Data {
110  public:
111   /**
112    * Returns the module specifier for this ModuleRequest.
113    */
114   Local<String> GetSpecifier() const;
115 
116   /**
117    * Returns the source code offset of this module request.
118    * Use Module::SourceOffsetToLocation to convert this to line/column numbers.
119    */
120   int GetSourceOffset() const;
121 
122   /**
123    * Contains the import assertions for this request in the form:
124    * [key1, value1, source_offset1, key2, value2, source_offset2, ...].
125    * The keys and values are of type v8::String, and the source offsets are of
126    * type Int32. Use Module::SourceOffsetToLocation to convert the source
127    * offsets to Locations with line/column numbers.
128    *
129    * All assertions present in the module request will be supplied in this
130    * list, regardless of whether they are supported by the host. Per
131    * https://tc39.es/proposal-import-attributes/#sec-hostgetsupportedimportattributes,
132    * hosts are expected to throw for assertions that they do not support (as
133    * opposed to, for example, ignoring them).
134    */
135   Local<FixedArray> GetImportAssertions() const;
136 
137   V8_INLINE static ModuleRequest* Cast(Data* data);
138 
139  private:
140   static void CheckCast(Data* obj);
141 };
142 
143 /**
144  * A compiled JavaScript module.
145  */
146 class V8_EXPORT Module : public Data {
147  public:
148   /**
149    * The different states a module can be in.
150    *
151    * This corresponds to the states used in ECMAScript except that "evaluated"
152    * is split into kEvaluated and kErrored, indicating success and failure,
153    * respectively.
154    */
155   enum Status {
156     kUninstantiated,
157     kInstantiating,
158     kInstantiated,
159     kEvaluating,
160     kEvaluated,
161     kErrored
162   };
163 
164   /**
165    * Returns the module's current status.
166    */
167   Status GetStatus() const;
168 
169   /**
170    * For a module in kErrored status, this returns the corresponding exception.
171    */
172   Local<Value> GetException() const;
173 
174   /**
175    * Returns the ModuleRequests for this module.
176    */
177   Local<FixedArray> GetModuleRequests() const;
178 
179   /**
180    * For the given source text offset in this module, returns the corresponding
181    * Location with line and column numbers.
182    */
183   Location SourceOffsetToLocation(int offset) const;
184 
185   /**
186    * Returns the identity hash for this object.
187    */
188   int GetIdentityHash() const;
189 
190   using ResolveModuleCallback = MaybeLocal<Module> (*)(
191       Local<Context> context, Local<String> specifier,
192       Local<FixedArray> import_assertions, Local<Module> referrer);
193 
194   /**
195    * Instantiates the module and its dependencies.
196    *
197    * Returns an empty Maybe<bool> if an exception occurred during
198    * instantiation. (In the case where the callback throws an exception, that
199    * exception is propagated.)
200    */
201   V8_WARN_UNUSED_RESULT Maybe<bool> InstantiateModule(
202       Local<Context> context, ResolveModuleCallback callback);
203 
204   /**
205    * Evaluates the module and its dependencies.
206    *
207    * If status is kInstantiated, run the module's code and return a Promise
208    * object. On success, set status to kEvaluated and resolve the Promise with
209    * the completion value; on failure, set status to kErrored and reject the
210    * Promise with the error.
211    *
212    * If IsGraphAsync() is false, the returned Promise is settled.
213    */
214   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context);
215 
216   /**
217    * Returns the namespace object of this module.
218    *
219    * The module's status must be at least kInstantiated.
220    */
221   Local<Value> GetModuleNamespace();
222 
223   /**
224    * Returns the corresponding context-unbound module script.
225    *
226    * The module must be unevaluated, i.e. its status must not be kEvaluating,
227    * kEvaluated or kErrored.
228    */
229   Local<UnboundModuleScript> GetUnboundModuleScript();
230 
231   /**
232    * Returns the underlying script's id.
233    *
234    * The module must be a SourceTextModule and must not have a kErrored status.
235    */
236   int ScriptId() const;
237 
238   /**
239    * Returns whether this module or any of its requested modules is async,
240    * i.e. contains top-level await.
241    *
242    * The module's status must be at least kInstantiated.
243    */
244   bool IsGraphAsync() const;
245 
246   /**
247    * Returns whether the module is a SourceTextModule.
248    */
249   bool IsSourceTextModule() const;
250 
251   /**
252    * Returns whether the module is a SyntheticModule.
253    */
254   bool IsSyntheticModule() const;
255 
256   /*
257    * Callback defined in the embedder.  This is responsible for setting
258    * the module's exported values with calls to SetSyntheticModuleExport().
259    * The callback must return a resolved Promise to indicate success (where no
260    * exception was thrown) and return an empy MaybeLocal to indicate falure
261    * (where an exception was thrown).
262    */
263   using SyntheticModuleEvaluationSteps =
264       MaybeLocal<Value> (*)(Local<Context> context, Local<Module> module);
265 
266   /**
267    * Creates a new SyntheticModule with the specified export names, where
268    * evaluation_steps will be executed upon module evaluation.
269    * export_names must not contain duplicates.
270    * module_name is used solely for logging/debugging and doesn't affect module
271    * behavior.
272    */
273   static Local<Module> CreateSyntheticModule(
274       Isolate* isolate, Local<String> module_name,
275       const std::vector<Local<String>>& export_names,
276       SyntheticModuleEvaluationSteps evaluation_steps);
277 
278   /**
279    * Set this module's exported value for the name export_name to the specified
280    * export_value. This method must be called only on Modules created via
281    * CreateSyntheticModule.  An error will be thrown if export_name is not one
282    * of the export_names that were passed in that CreateSyntheticModule call.
283    * Returns Just(true) on success, Nothing<bool>() if an error was thrown.
284    */
285   V8_WARN_UNUSED_RESULT Maybe<bool> SetSyntheticModuleExport(
286       Isolate* isolate, Local<String> export_name, Local<Value> export_value);
287 
288   V8_INLINE static Module* Cast(Data* data);
289 
290  private:
291   static void CheckCast(Data* obj);
292 };
293 
294 /**
295  * A compiled JavaScript script, tied to a Context which was active when the
296  * script was compiled.
297  */
298 class V8_EXPORT Script {
299  public:
300   /**
301    * A shorthand for ScriptCompiler::Compile().
302    */
303   static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
304       Local<Context> context, Local<String> source,
305       ScriptOrigin* origin = nullptr);
306 
307   /**
308    * Runs the script returning the resulting value. It will be run in the
309    * context in which it was created (ScriptCompiler::CompileBound or
310    * UnboundScript::BindToCurrentContext()).
311    */
312   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context);
313   V8_WARN_UNUSED_RESULT MaybeLocal<Value> Run(Local<Context> context,
314                                               Local<Data> host_defined_options);
315 
316   /**
317    * Returns the corresponding context-unbound script.
318    */
319   Local<UnboundScript> GetUnboundScript();
320 
321   /**
322    * The name that was passed by the embedder as ResourceName to the
323    * ScriptOrigin. This can be either a v8::String or v8::Undefined.
324    */
325   Local<Value> GetResourceName();
326 };
327 
328 enum class ScriptType { kClassic, kModule };
329 
330 /**
331  * For compiling scripts.
332  */
333 class V8_EXPORT ScriptCompiler {
334  public:
335   class ConsumeCodeCacheTask;
336 
337   /**
338    * Compilation data that the embedder can cache and pass back to speed up
339    * future compilations. The data is produced if the CompilerOptions passed to
340    * the compilation functions in ScriptCompiler contains produce_data_to_cache
341    * = true. The data to cache can then can be retrieved from
342    * UnboundScript.
343    */
344   struct V8_EXPORT CachedData {
345     enum BufferPolicy { BufferNotOwned, BufferOwned };
346 
CachedDataCachedData347     CachedData()
348         : data(nullptr),
349           length(0),
350           rejected(false),
351           buffer_policy(BufferNotOwned) {}
352 
353     // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
354     // data and guarantees that it stays alive until the CachedData object is
355     // destroyed. If the policy is BufferOwned, the given data will be deleted
356     // (with delete[]) when the CachedData object is destroyed.
357     CachedData(const uint8_t* data, int length,
358                BufferPolicy buffer_policy = BufferNotOwned);
359     ~CachedData();
360     // TODO(marja): Async compilation; add constructors which take a callback
361     // which will be called when V8 no longer needs the data.
362     const uint8_t* data;
363     int length;
364     bool rejected;
365     BufferPolicy buffer_policy;
366 
367     // Prevent copying.
368     CachedData(const CachedData&) = delete;
369     CachedData& operator=(const CachedData&) = delete;
370   };
371 
372   /**
373    * Source code which can be then compiled to a UnboundScript or Script.
374    */
375   class Source {
376    public:
377     // Source takes ownership of both CachedData and CodeCacheConsumeTask.
378     // The caller *must* ensure that the cached data is from a trusted source.
379     V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
380                      CachedData* cached_data = nullptr,
381                      ConsumeCodeCacheTask* consume_cache_task = nullptr);
382     // Source takes ownership of both CachedData and CodeCacheConsumeTask.
383     V8_INLINE explicit Source(
384         Local<String> source_string, CachedData* cached_data = nullptr,
385         ConsumeCodeCacheTask* consume_cache_task = nullptr);
386     V8_INLINE ~Source() = default;
387 
388     // Ownership of the CachedData or its buffers is *not* transferred to the
389     // caller. The CachedData object is alive as long as the Source object is
390     // alive.
391     V8_INLINE const CachedData* GetCachedData() const;
392 
393     V8_INLINE const ScriptOriginOptions& GetResourceOptions() const;
394 
395    private:
396     friend class ScriptCompiler;
397 
398     Local<String> source_string;
399 
400     // Origin information
401     Local<Value> resource_name;
402     int resource_line_offset;
403     int resource_column_offset;
404     ScriptOriginOptions resource_options;
405     Local<Value> source_map_url;
406     Local<Data> host_defined_options;
407 
408     // Cached data from previous compilation (if a kConsume*Cache flag is
409     // set), or hold newly generated cache data (kProduce*Cache flags) are
410     // set when calling a compile method.
411     std::unique_ptr<CachedData> cached_data;
412     std::unique_ptr<ConsumeCodeCacheTask> consume_cache_task;
413   };
414 
415   /**
416    * For streaming incomplete script data to V8. The embedder should implement a
417    * subclass of this class.
418    */
419   class V8_EXPORT ExternalSourceStream {
420    public:
421     virtual ~ExternalSourceStream() = default;
422 
423     /**
424      * V8 calls this to request the next chunk of data from the embedder. This
425      * function will be called on a background thread, so it's OK to block and
426      * wait for the data, if the embedder doesn't have data yet. Returns the
427      * length of the data returned. When the data ends, GetMoreData should
428      * return 0. Caller takes ownership of the data.
429      *
430      * When streaming UTF-8 data, V8 handles multi-byte characters split between
431      * two data chunks, but doesn't handle multi-byte characters split between
432      * more than two data chunks. The embedder can avoid this problem by always
433      * returning at least 2 bytes of data.
434      *
435      * When streaming UTF-16 data, V8 does not handle characters split between
436      * two data chunks. The embedder has to make sure that chunks have an even
437      * length.
438      *
439      * If the embedder wants to cancel the streaming, they should make the next
440      * GetMoreData call return 0. V8 will interpret it as end of data (and most
441      * probably, parsing will fail). The streaming task will return as soon as
442      * V8 has parsed the data it received so far.
443      */
444     virtual size_t GetMoreData(const uint8_t** src) = 0;
445   };
446 
447   /**
448    * Source code which can be streamed into V8 in pieces. It will be parsed
449    * while streaming and compiled after parsing has completed. StreamedSource
450    * must be kept alive while the streaming task is run (see ScriptStreamingTask
451    * below).
452    */
453   class V8_EXPORT StreamedSource {
454    public:
455     enum Encoding { ONE_BYTE, TWO_BYTE, UTF8, WINDOWS_1252 };
456 
457     StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream,
458                    Encoding encoding);
459     ~StreamedSource();
460 
impl()461     internal::ScriptStreamingData* impl() const { return impl_.get(); }
462 
463     // Prevent copying.
464     StreamedSource(const StreamedSource&) = delete;
465     StreamedSource& operator=(const StreamedSource&) = delete;
466 
467    private:
468     std::unique_ptr<internal::ScriptStreamingData> impl_;
469   };
470 
471   /**
472    * A streaming task which the embedder must run on a background thread to
473    * stream scripts into V8. Returned by ScriptCompiler::StartStreaming.
474    */
475   class V8_EXPORT ScriptStreamingTask final {
476    public:
477     void Run();
478 
479    private:
480     friend class ScriptCompiler;
481 
ScriptStreamingTask(internal::ScriptStreamingData * data)482     explicit ScriptStreamingTask(internal::ScriptStreamingData* data)
483         : data_(data) {}
484 
485     internal::ScriptStreamingData* data_;
486   };
487 
488   /**
489    * A task which the embedder must run on a background thread to
490    * consume a V8 code cache. Returned by
491    * ScriptCompiler::StarConsumingCodeCache.
492    */
493   class V8_EXPORT ConsumeCodeCacheTask final {
494    public:
495     ~ConsumeCodeCacheTask();
496 
497     void Run();
498 
499    private:
500     friend class ScriptCompiler;
501 
502     explicit ConsumeCodeCacheTask(
503         std::unique_ptr<internal::BackgroundDeserializeTask> impl);
504 
505     std::unique_ptr<internal::BackgroundDeserializeTask> impl_;
506   };
507 
508   enum CompileOptions {
509     kNoCompileOptions = 0,
510     kConsumeCodeCache,
511     kEagerCompile
512   };
513 
514   /**
515    * The reason for which we are not requesting or providing a code cache.
516    */
517   enum NoCacheReason {
518     kNoCacheNoReason = 0,
519     kNoCacheBecauseCachingDisabled,
520     kNoCacheBecauseNoResource,
521     kNoCacheBecauseInlineScript,
522     kNoCacheBecauseModule,
523     kNoCacheBecauseStreamingSource,
524     kNoCacheBecauseInspector,
525     kNoCacheBecauseScriptTooSmall,
526     kNoCacheBecauseCacheTooCold,
527     kNoCacheBecauseV8Extension,
528     kNoCacheBecauseExtensionModule,
529     kNoCacheBecausePacScript,
530     kNoCacheBecauseInDocumentWrite,
531     kNoCacheBecauseResourceWithNoCacheHandler,
532     kNoCacheBecauseDeferredProduceCodeCache
533   };
534 
535   /**
536    * Compiles the specified script (context-independent).
537    * Cached data as part of the source object can be optionally produced to be
538    * consumed later to speed up compilation of identical source scripts.
539    *
540    * Note that when producing cached data, the source must point to NULL for
541    * cached data. When consuming cached data, the cached data must have been
542    * produced by the same version of V8, and the embedder needs to ensure the
543    * cached data is the correct one for the given script.
544    *
545    * \param source Script source code.
546    * \return Compiled script object (context independent; for running it must be
547    *   bound to a context).
548    */
549   static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundScript(
550       Isolate* isolate, Source* source,
551       CompileOptions options = kNoCompileOptions,
552       NoCacheReason no_cache_reason = kNoCacheNoReason);
553 
554   /**
555    * Compiles the specified script (bound to current context).
556    *
557    * \param source Script source code.
558    * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
559    *   using pre_data speeds compilation if it's done multiple times.
560    *   Owned by caller, no references are kept when this function returns.
561    * \return Compiled script object, bound to the context that was active
562    *   when this function was called. When run it will always use this
563    *   context.
564    */
565   static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
566       Local<Context> context, Source* source,
567       CompileOptions options = kNoCompileOptions,
568       NoCacheReason no_cache_reason = kNoCacheNoReason);
569 
570   /**
571    * Returns a task which streams script data into V8, or NULL if the script
572    * cannot be streamed. The user is responsible for running the task on a
573    * background thread and deleting it. When ran, the task starts parsing the
574    * script, and it will request data from the StreamedSource as needed. When
575    * ScriptStreamingTask::Run exits, all data has been streamed and the script
576    * can be compiled (see Compile below).
577    *
578    * This API allows to start the streaming with as little data as possible, and
579    * the remaining data (for example, the ScriptOrigin) is passed to Compile.
580    */
581   static ScriptStreamingTask* StartStreaming(
582       Isolate* isolate, StreamedSource* source,
583       ScriptType type = ScriptType::kClassic);
584 
585   static ConsumeCodeCacheTask* StartConsumingCodeCache(
586       Isolate* isolate, std::unique_ptr<CachedData> source);
587 
588   /**
589    * Compiles a streamed script (bound to current context).
590    *
591    * This can only be called after the streaming has finished
592    * (ScriptStreamingTask has been run). V8 doesn't construct the source string
593    * during streaming, so the embedder needs to pass the full source here.
594    */
595   static V8_WARN_UNUSED_RESULT MaybeLocal<Script> Compile(
596       Local<Context> context, StreamedSource* source,
597       Local<String> full_source_string, const ScriptOrigin& origin);
598 
599   /**
600    * Return a version tag for CachedData for the current V8 version & flags.
601    *
602    * This value is meant only for determining whether a previously generated
603    * CachedData instance is still valid; the tag has no other meaing.
604    *
605    * Background: The data carried by CachedData may depend on the exact
606    *   V8 version number or current compiler flags. This means that when
607    *   persisting CachedData, the embedder must take care to not pass in
608    *   data from another V8 version, or the same version with different
609    *   features enabled.
610    *
611    *   The easiest way to do so is to clear the embedder's cache on any
612    *   such change.
613    *
614    *   Alternatively, this tag can be stored alongside the cached data and
615    *   compared when it is being used.
616    */
617   static uint32_t CachedDataVersionTag();
618 
619   /**
620    * Compile an ES module, returning a Module that encapsulates
621    * the compiled code.
622    *
623    * Corresponds to the ParseModule abstract operation in the
624    * ECMAScript specification.
625    */
626   static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
627       Isolate* isolate, Source* source,
628       CompileOptions options = kNoCompileOptions,
629       NoCacheReason no_cache_reason = kNoCacheNoReason);
630 
631   /**
632    * Compiles a streamed module script.
633    *
634    * This can only be called after the streaming has finished
635    * (ScriptStreamingTask has been run). V8 doesn't construct the source string
636    * during streaming, so the embedder needs to pass the full source here.
637    */
638   static V8_WARN_UNUSED_RESULT MaybeLocal<Module> CompileModule(
639       Local<Context> context, StreamedSource* v8_source,
640       Local<String> full_source_string, const ScriptOrigin& origin);
641 
642   /**
643    * Compile a function for a given context. This is equivalent to running
644    *
645    * with (obj) {
646    *   return function(args) { ... }
647    * }
648    *
649    * It is possible to specify multiple context extensions (obj in the above
650    * example).
651    */
652   static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInContext(
653       Local<Context> context, Source* source, size_t arguments_count,
654       Local<String> arguments[], size_t context_extension_count,
655       Local<Object> context_extensions[],
656       CompileOptions options = kNoCompileOptions,
657       NoCacheReason no_cache_reason = kNoCacheNoReason,
658       Local<ScriptOrModule>* script_or_module_out = nullptr);
659   static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunction(
660       Local<Context> context, Source* source, size_t arguments_count = 0,
661       Local<String> arguments[] = nullptr, size_t context_extension_count = 0,
662       Local<Object> context_extensions[] = nullptr,
663       CompileOptions options = kNoCompileOptions,
664       NoCacheReason no_cache_reason = kNoCacheNoReason);
665 
666   /**
667    * Creates and returns code cache for the specified unbound_script.
668    * This will return nullptr if the script cannot be serialized. The
669    * CachedData returned by this function should be owned by the caller.
670    */
671   static CachedData* CreateCodeCache(Local<UnboundScript> unbound_script);
672 
673   /**
674    * Creates and returns code cache for the specified unbound_module_script.
675    * This will return nullptr if the script cannot be serialized. The
676    * CachedData returned by this function should be owned by the caller.
677    */
678   static CachedData* CreateCodeCache(
679       Local<UnboundModuleScript> unbound_module_script);
680 
681   /**
682    * Creates and returns code cache for the specified function that was
683    * previously produced by CompileFunction.
684    * This will return nullptr if the script cannot be serialized. The
685    * CachedData returned by this function should be owned by the caller.
686    */
687   static CachedData* CreateCodeCacheForFunction(Local<Function> function);
688 
689  private:
690   static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
691       Isolate* isolate, Source* source, CompileOptions options,
692       NoCacheReason no_cache_reason);
693 
694   static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInternal(
695       Local<Context> context, Source* source, size_t arguments_count,
696       Local<String> arguments[], size_t context_extension_count,
697       Local<Object> context_extensions[], CompileOptions options,
698       NoCacheReason no_cache_reason,
699       Local<ScriptOrModule>* script_or_module_out);
700 };
701 
Source(Local<String> string,const ScriptOrigin & origin,CachedData * data,ConsumeCodeCacheTask * consume_cache_task)702 ScriptCompiler::Source::Source(Local<String> string, const ScriptOrigin& origin,
703                                CachedData* data,
704                                ConsumeCodeCacheTask* consume_cache_task)
705     : source_string(string),
706       resource_name(origin.ResourceName()),
707       resource_line_offset(origin.LineOffset()),
708       resource_column_offset(origin.ColumnOffset()),
709       resource_options(origin.Options()),
710       source_map_url(origin.SourceMapUrl()),
711       host_defined_options(origin.GetHostDefinedOptions()),
712       cached_data(data),
713       consume_cache_task(consume_cache_task) {}
714 
Source(Local<String> string,CachedData * data,ConsumeCodeCacheTask * consume_cache_task)715 ScriptCompiler::Source::Source(Local<String> string, CachedData* data,
716                                ConsumeCodeCacheTask* consume_cache_task)
717     : source_string(string),
718       cached_data(data),
719       consume_cache_task(consume_cache_task) {}
720 
GetCachedData()721 const ScriptCompiler::CachedData* ScriptCompiler::Source::GetCachedData()
722     const {
723   return cached_data.get();
724 }
725 
GetResourceOptions()726 const ScriptOriginOptions& ScriptCompiler::Source::GetResourceOptions() const {
727   return resource_options;
728 }
729 
Cast(Data * data)730 ModuleRequest* ModuleRequest::Cast(Data* data) {
731 #ifdef V8_ENABLE_CHECKS
732   CheckCast(data);
733 #endif
734   return reinterpret_cast<ModuleRequest*>(data);
735 }
736 
Cast(Data * data)737 Module* Module::Cast(Data* data) {
738 #ifdef V8_ENABLE_CHECKS
739   CheckCast(data);
740 #endif
741   return reinterpret_cast<Module*>(data);
742 }
743 
744 }  // namespace v8
745 
746 #endif  // INCLUDE_V8_SCRIPT_H_
747