v8 14.1.146 (node 25.0.0)
V8 is Google's open source JavaScript engine
Loading...
Searching...
No Matches
v8-script.h
Go to the documentation of this file.
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 <tuple>
13#include <vector>
14
15#include "v8-callbacks.h" // NOLINT(build/include_directory)
16#include "v8-data.h" // NOLINT(build/include_directory)
17#include "v8-local-handle.h" // NOLINT(build/include_directory)
18#include "v8-maybe.h" // NOLINT(build/include_directory)
19#include "v8-memory-span.h" // NOLINT(build/include_directory)
20#include "v8-message.h" // NOLINT(build/include_directory)
21#include "v8config.h" // NOLINT(build/include_directory)
22
23namespace v8 {
24
25class Function;
26class Message;
27class Object;
28class PrimitiveArray;
29class Script;
30
31namespace internal {
32class BackgroundDeserializeTask;
33struct ScriptStreamingData;
34} // namespace internal
35
36/**
37 * A container type that holds relevant metadata for module loading.
38 *
39 * This is passed back to the embedder as part of
40 * HostImportModuleDynamicallyCallback for module loading.
41 */
43 public:
44 /**
45 * The name that was passed by the embedder as ResourceName to the
46 * ScriptOrigin. This can be either a v8::String or v8::Undefined.
47 */
49
50 /**
51 * The options that were passed by the embedder as HostDefinedOptions to
52 * the ScriptOrigin.
53 */
55};
56
57/**
58 * A compiled JavaScript script, not yet tied to a Context.
59 */
61 public:
62 /**
63 * Binds the script to the currently entered context.
64 */
66
67 int GetId() const;
69
70 /**
71 * Data read from magic sourceURL comments.
72 */
74 /**
75 * Data read from magic sourceMappingURL comments.
76 */
78
79 /**
80 * Returns zero based line number of the code_pos location in the script.
81 * -1 will be returned if no information available.
82 */
83 int GetLineNumber(int code_pos = 0);
84
85 /**
86 * Returns zero based column number of the code_pos location in the script.
87 * -1 will be returned if no information available.
88 */
89 int GetColumnNumber(int code_pos = 0);
90
91 static const int kNoScriptId = 0;
92};
93
94/**
95 * A compiled JavaScript module, not yet tied to a Context.
96 */
98 public:
99 /**
100 * Data read from magic sourceURL comments.
101 */
103 /**
104 * Data read from magic sourceMappingURL comments.
105 */
107};
108
109/**
110 * A location in JavaScript source.
111 */
113 public:
114 int GetLineNumber() { return line_number_; }
115 int GetColumnNumber() { return column_number_; }
116
117 Location(int line_number, int column_number)
118 : line_number_(line_number), column_number_(column_number) {}
119
120 private:
121 int line_number_;
122 int column_number_;
123};
124
126 public:
127 /**
128 * Returns the module specifier for this ModuleRequest.
129 */
131
132 /**
133 * Returns the module import phase for this ModuleRequest.
134 */
136
137 /**
138 * Returns the source code offset of this module request.
139 * Use Module::SourceOffsetToLocation to convert this to line/column numbers.
140 */
141 int GetSourceOffset() const;
142
143 /**
144 * Contains the import attributes for this request in the form:
145 * [key1, value1, source_offset1, key2, value2, source_offset2, ...].
146 * The keys and values are of type v8::String, and the source offsets are of
147 * type Int32. Use Module::SourceOffsetToLocation to convert the source
148 * offsets to Locations with line/column numbers.
149 *
150 * All attributes present in the module request will be supplied in this
151 * list, regardless of whether they are supported by the host. Per
152 * https://tc39.es/proposal-import-attributes/#sec-hostgetsupportedimportattributes,
153 * hosts are expected to throw for attributes that they do not support (as
154 * opposed to, for example, ignoring them).
155 */
157
158 V8_DEPRECATED("Use GetImportAttributes instead")
160 return GetImportAttributes();
161 }
162
163 V8_INLINE static ModuleRequest* Cast(Data* data);
164
165 private:
166 static void CheckCast(Data* obj);
167};
168
169/**
170 * A compiled JavaScript module.
171 */
172class V8_EXPORT Module : public Data {
173 public:
174 /**
175 * The different states a module can be in.
176 *
177 * This corresponds to the states used in ECMAScript except that "evaluated"
178 * is split into kEvaluated and kErrored, indicating success and failure,
179 * respectively.
180 */
181 enum Status {
188 };
189
190 /**
191 * Returns the module's current status.
192 */
194
195 /**
196 * For a module in kErrored status, this returns the corresponding exception.
197 */
199
200 /**
201 * Returns the ModuleRequests for this module.
202 */
204
205 /**
206 * For the given source text offset in this module, returns the corresponding
207 * Location with line and column numbers.
208 */
210
211 /**
212 * Returns the identity hash for this object.
213 */
214 int GetIdentityHash() const;
215
216 using ResolveModuleCallback = MaybeLocal<Module> (*)(
217 Local<Context> context, Local<String> specifier,
218 Local<FixedArray> import_attributes, Local<Module> referrer);
219 using ResolveSourceCallback = MaybeLocal<Object> (*)(
220 Local<Context> context, Local<String> specifier,
221 Local<FixedArray> import_attributes, Local<Module> referrer);
222
223 /**
224 * Instantiates the module and its dependencies.
225 *
226 * Returns an empty Maybe<bool> if an exception occurred during
227 * instantiation. (In the case where the callback throws an exception, that
228 * exception is propagated.)
229 */
231 Local<Context> context, ResolveModuleCallback module_callback,
232 ResolveSourceCallback source_callback = nullptr);
233
234 /**
235 * Evaluates the module and its dependencies.
236 *
237 * If status is kInstantiated, run the module's code and return a Promise
238 * object. On success, set status to kEvaluated and resolve the Promise with
239 * the completion value; on failure, set status to kErrored and reject the
240 * Promise with the error.
241 *
242 * If IsGraphAsync() is false, the returned Promise is settled.
243 */
245
246 /**
247 * Returns the namespace object of this module.
248 *
249 * The module's status must be at least kInstantiated.
250 */
252
253 /**
254 * Returns the corresponding context-unbound module script.
255 *
256 * The module must be unevaluated, i.e. its status must not be kEvaluating,
257 * kEvaluated or kErrored.
258 */
260
261 /**
262 * Returns the underlying script's id.
263 *
264 * The module must be a SourceTextModule and must not have a kErrored status.
265 */
266 int ScriptId() const;
267
268 /**
269 * Returns whether this module or any of its requested modules is async,
270 * i.e. contains top-level await.
271 *
272 * The module's status must be at least kInstantiated.
273 */
274 bool IsGraphAsync() const;
275
276 /**
277 * Returns whether this module is individually asynchronous (for example,
278 * if it's a Source Text Module Record containing a top-level await).
279 * See [[HasTLA]] in https://tc39.es/ecma262/#sec-cyclic-module-records
280 */
281 bool HasTopLevelAwait() const;
282
283 /**
284 * Returns whether the module is a SourceTextModule.
285 */
286 bool IsSourceTextModule() const;
287
288 /**
289 * Returns whether the module is a SyntheticModule.
290 */
291 bool IsSyntheticModule() const;
292
293 /*
294 * Callback defined in the embedder. This is responsible for setting
295 * the module's exported values with calls to SetSyntheticModuleExport().
296 * The callback must return a resolved Promise to indicate success (where no
297 * exception was thrown) and return an empy MaybeLocal to indicate falure
298 * (where an exception was thrown).
299 */
300 using SyntheticModuleEvaluationSteps =
301 MaybeLocal<Value> (*)(Local<Context> context, Local<Module> module);
302
303 /**
304 * Creates a new SyntheticModule with the specified export names, where
305 * evaluation_steps will be executed upon module evaluation.
306 * export_names must not contain duplicates.
307 * module_name is used solely for logging/debugging and doesn't affect module
308 * behavior.
309 */
311 Isolate* isolate, Local<String> module_name,
312 const MemorySpan<const Local<String>>& export_names,
313 SyntheticModuleEvaluationSteps evaluation_steps);
314
315 /**
316 * Set this module's exported value for the name export_name to the specified
317 * export_value. This method must be called only on Modules created via
318 * CreateSyntheticModule. An error will be thrown if export_name is not one
319 * of the export_names that were passed in that CreateSyntheticModule call.
320 * Returns Just(true) on success, Nothing<bool>() if an error was thrown.
321 */
323 Isolate* isolate, Local<String> export_name, Local<Value> export_value);
324
325 /**
326 * Search the modules requested directly or indirectly by the module for
327 * any top-level await that has not yet resolved. If there is any, the
328 * returned pair of vectors (of equal size) contain the unresolved module
329 * and corresponding message with the pending top-level await.
330 * An embedder may call this before exiting to improve error messages.
331 */
332 std::pair<LocalVector<Module>, LocalVector<Message>>
334
335 V8_INLINE static Module* Cast(Data* data);
336
337 private:
338 static void CheckCast(Data* obj);
339};
340
342 public:
343 /**
344 * Returns the positions of lazy functions which were compiled and executed.
345 */
346 std::vector<int> GetCompileHints(Isolate* isolate) const;
347};
348
349/**
350 * A compiled JavaScript script, tied to a Context which was active when the
351 * script was compiled.
352 */
353class V8_EXPORT Script : public Data {
354 public:
355 /**
356 * A shorthand for ScriptCompiler::Compile().
357 */
359 Local<Context> context, Local<String> source,
360 ScriptOrigin* origin = nullptr);
361
362 /**
363 * Runs the script returning the resulting value. It will be run in the
364 * context in which it was created (ScriptCompiler::CompileBound or
365 * UnboundScript::BindToCurrentContext()).
366 */
369 Local<Data> host_defined_options);
370
371 /**
372 * Returns the corresponding context-unbound script.
373 */
375
376 /**
377 * The name that was passed by the embedder as ResourceName to the
378 * ScriptOrigin. This can be either a v8::String or v8::Undefined.
379 */
381
382 /**
383 * If the script was compiled, returns the positions of lazy functions which
384 * were eventually compiled and executed.
385 */
386 V8_DEPRECATE_SOON("Use GetCompileHintsCollector instead")
388
389 /**
390 * Get a compile hints collector object which we can use later for retrieving
391 * compile hints (= positions of lazy functions which were compiled and
392 * executed).
393 */
395};
396
398
399/**
400 * For compiling scripts.
401 */
403 public:
404 class ConsumeCodeCacheTask;
405
406 /**
407 * Compilation data that the embedder can cache and pass back to speed up
408 * future compilations. The data is produced if the CompilerOptions passed to
409 * the compilation functions in ScriptCompiler contains produce_data_to_cache
410 * = true. The data to cache can then can be retrieved from
411 * UnboundScript.
412 */
415
417 : data(nullptr),
418 length(0),
419 rejected(false),
421
422 // If buffer_policy is BufferNotOwned, the caller keeps the ownership of
423 // data and guarantees that it stays alive until the CachedData object is
424 // destroyed. If the policy is BufferOwned, the given data will be deleted
425 // (with delete[]) when the CachedData object is destroyed.
426 CachedData(const uint8_t* data, int length,
427 BufferPolicy buffer_policy = BufferNotOwned);
429
431 // Don't change order/existing values of this enum since it keys into the
432 // `code_cache_reject_reason` histogram. Append-only!
442
443 // This should always point at the last real enum value.
445 };
446
447 // Check if the CachedData can be loaded in the given isolate.
449
450 // TODO(marja): Async compilation; add constructors which take a callback
451 // which will be called when V8 no longer needs the data.
452 const uint8_t* data;
456
457 // Prevent copying.
458 CachedData(const CachedData&) = delete;
459 CachedData& operator=(const CachedData&) = delete;
460 };
461
463 // V8 did not attempt to find this script in its in-memory cache.
465
466 // V8 found a previously compiled copy of this script in its in-memory
467 // cache. Any data generated by a streaming compilation or background
468 // deserialization was abandoned.
469 kHit,
470
471 // V8 didn't have any previously compiled data for this script.
472 kMiss,
473
474 // V8 had some previously compiled data for an identical script, but the
475 // data was incomplete.
476 kPartial,
477 };
478
479 // Details about what happened during a compilation.
483
484 static constexpr int64_t kTimeNotMeasured = -1;
487 };
488
489 /**
490 * Source code which can be then compiled to a UnboundScript or Script.
491 */
492 class Source {
493 public:
494 // Source takes ownership of both CachedData and CodeCacheConsumeTask.
495 // The caller *must* ensure that the cached data is from a trusted source.
496 V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
497 CachedData* cached_data = nullptr,
498 ConsumeCodeCacheTask* consume_cache_task = nullptr);
499 // Source takes ownership of both CachedData and CodeCacheConsumeTask.
500 V8_INLINE explicit Source(
501 Local<String> source_string, CachedData* cached_data = nullptr,
502 ConsumeCodeCacheTask* consume_cache_task = nullptr);
503 V8_INLINE Source(Local<String> source_string, const ScriptOrigin& origin,
504 CompileHintCallback callback, void* callback_data);
505 V8_INLINE ~Source() = default;
506
507 // Ownership of the CachedData or its buffers is *not* transferred to the
508 // caller. The CachedData object is alive as long as the Source object is
509 // alive.
510 V8_INLINE const CachedData* GetCachedData() const;
511
513
515
516 private:
517 friend class ScriptCompiler;
518
519 Local<String> source_string;
520
521 // Origin information
522 Local<Value> resource_name;
523 int resource_line_offset = -1;
524 int resource_column_offset = -1;
525 ScriptOriginOptions resource_options;
526 Local<Value> source_map_url;
527 Local<Data> host_defined_options;
528
529 // Cached data from previous compilation (if a kConsume*Cache flag is
530 // set), or hold newly generated cache data (kProduce*Cache flags) are
531 // set when calling a compile method.
532 std::unique_ptr<CachedData> cached_data;
533 std::unique_ptr<ConsumeCodeCacheTask> consume_cache_task;
534
535 // For requesting compile hints from the embedder.
536 CompileHintCallback compile_hint_callback = nullptr;
537 void* compile_hint_callback_data = nullptr;
538
539 // V8 writes this data and never reads it. It exists only to be informative
540 // to the embedder.
541 CompilationDetails compilation_details;
542 };
543
544 /**
545 * For streaming incomplete script data to V8. The embedder should implement a
546 * subclass of this class.
547 */
549 public:
550 virtual ~ExternalSourceStream() = default;
551
552 /**
553 * V8 calls this to request the next chunk of data from the embedder. This
554 * function will be called on a background thread, so it's OK to block and
555 * wait for the data, if the embedder doesn't have data yet. Returns the
556 * length of the data returned. When the data ends, GetMoreData should
557 * return 0. Caller takes ownership of the data.
558 *
559 * When streaming UTF-8 data, V8 handles multi-byte characters split between
560 * two data chunks, but doesn't handle multi-byte characters split between
561 * more than two data chunks. The embedder can avoid this problem by always
562 * returning at least 2 bytes of data.
563 *
564 * When streaming UTF-16 data, V8 does not handle characters split between
565 * two data chunks. The embedder has to make sure that chunks have an even
566 * length.
567 *
568 * If the embedder wants to cancel the streaming, they should make the next
569 * GetMoreData call return 0. V8 will interpret it as end of data (and most
570 * probably, parsing will fail). The streaming task will return as soon as
571 * V8 has parsed the data it received so far.
572 */
573 virtual size_t GetMoreData(const uint8_t** src) = 0;
574 };
575
576 /**
577 * Source code which can be streamed into V8 in pieces. It will be parsed
578 * while streaming and compiled after parsing has completed. StreamedSource
579 * must be kept alive while the streaming task is run (see ScriptStreamingTask
580 * below).
581 */
583 public:
585
586 StreamedSource(std::unique_ptr<ExternalSourceStream> source_stream,
587 Encoding encoding);
589
590 internal::ScriptStreamingData* impl() const { return impl_.get(); }
591
592 // Prevent copying.
595
596 CompilationDetails& compilation_details() { return compilation_details_; }
597
598 private:
599 std::unique_ptr<internal::ScriptStreamingData> impl_;
600
601 // V8 writes this data and never reads it. It exists only to be informative
602 // to the embedder.
603 CompilationDetails compilation_details_;
604 };
605
606 /**
607 * A streaming task which the embedder must run on a background thread to
608 * stream scripts into V8. Returned by ScriptCompiler::StartStreaming.
609 */
610 class V8_EXPORT ScriptStreamingTask final {
611 public:
612 void Run();
613
614 private:
615 friend class ScriptCompiler;
616
617 explicit ScriptStreamingTask(internal::ScriptStreamingData* data)
618 : data_(data) {}
619
620 internal::ScriptStreamingData* data_;
621 };
622
623 /**
624 * A task which the embedder must run on a background thread to
625 * consume a V8 code cache. Returned by
626 * ScriptCompiler::StartConsumingCodeCache.
627 */
628 class V8_EXPORT ConsumeCodeCacheTask final {
629 public:
631
632 void Run();
633
634 /**
635 * Provides the source text string and origin information to the consumption
636 * task. May be called before, during, or after Run(). This step checks
637 * whether the script matches an existing script in the Isolate's
638 * compilation cache. To check whether such a script was found, call
639 * ShouldMergeWithExistingScript.
640 *
641 * The Isolate provided must be the same one used during
642 * StartConsumingCodeCache and must be currently entered on the thread that
643 * calls this function. The source text and origin provided in this step
644 * must precisely match those used later in the ScriptCompiler::Source that
645 * will contain this ConsumeCodeCacheTask.
646 */
647 void SourceTextAvailable(Isolate* isolate, Local<String> source_text,
648 const ScriptOrigin& origin);
649
650 /**
651 * Returns whether the embedder should call MergeWithExistingScript. This
652 * function may be called from any thread, any number of times, but its
653 * return value is only meaningful after SourceTextAvailable has completed.
654 */
656
657 /**
658 * Merges newly deserialized data into an existing script which was found
659 * during SourceTextAvailable. May be called only after Run() has completed.
660 * Can execute on any thread, like Run().
661 */
663
664 private:
665 friend class ScriptCompiler;
666
667 explicit ConsumeCodeCacheTask(
668 std::unique_ptr<internal::BackgroundDeserializeTask> impl);
669
670 std::unique_ptr<internal::BackgroundDeserializeTask> impl_;
671 };
672
681 };
682
683 static inline bool CompileOptionsIsValid(CompileOptions compile_options) {
684 // kConsumeCodeCache is mutually exclusive with all other flag bits.
685 if ((compile_options & kConsumeCodeCache) &&
686 compile_options != kConsumeCodeCache) {
687 return false;
688 }
689 // kEagerCompile is mutually exclusive with all other flag bits.
690 if ((compile_options & kEagerCompile) && compile_options != kEagerCompile) {
691 return false;
692 }
693 // We don't currently support producing and consuming compile hints at the
694 // same time.
695 constexpr int produce_and_consume = CompileOptions::kProduceCompileHints |
697 if ((compile_options & produce_and_consume) == produce_and_consume) {
698 return false;
699 }
700 return true;
701 }
702
703 /**
704 * The reason for which we are not requesting or providing a code cache.
705 */
723 };
724
725 /**
726 * Compiles the specified script (context-independent).
727 * Cached data as part of the source object can be optionally produced to be
728 * consumed later to speed up compilation of identical source scripts.
729 *
730 * Note that when producing cached data, the source must point to NULL for
731 * cached data. When consuming cached data, the cached data must have been
732 * produced by the same version of V8, and the embedder needs to ensure the
733 * cached data is the correct one for the given script.
734 *
735 * \param source Script source code.
736 * \return Compiled script object (context independent; for running it must be
737 * bound to a context).
738 */
740 Isolate* isolate, Source* source,
742 NoCacheReason no_cache_reason = kNoCacheNoReason);
743
744 /**
745 * Compiles the specified script (bound to current context).
746 *
747 * \param source Script source code.
748 * \param pre_data Pre-parsing data, as obtained by ScriptData::PreCompile()
749 * using pre_data speeds compilation if it's done multiple times.
750 * Owned by caller, no references are kept when this function returns.
751 * \return Compiled script object, bound to the context that was active
752 * when this function was called. When run it will always use this
753 * context.
754 */
756 Local<Context> context, Source* source,
758 NoCacheReason no_cache_reason = kNoCacheNoReason);
759
760 /**
761 * Returns a task which streams script data into V8, or NULL if the script
762 * cannot be streamed. The user is responsible for running the task on a
763 * background thread and deleting it. When ran, the task starts parsing the
764 * script, and it will request data from the StreamedSource as needed. When
765 * ScriptStreamingTask::Run exits, all data has been streamed and the script
766 * can be compiled (see Compile below).
767 *
768 * This API allows to start the streaming with as little data as possible, and
769 * the remaining data (for example, the ScriptOrigin) is passed to Compile.
770 */
771 static ScriptStreamingTask* StartStreaming(
772 Isolate* isolate, StreamedSource* source,
775 CompileHintCallback compile_hint_callback = nullptr,
776 void* compile_hint_callback_data = nullptr);
777
778 static ConsumeCodeCacheTask* StartConsumingCodeCache(
779 Isolate* isolate, std::unique_ptr<CachedData> source);
780 static ConsumeCodeCacheTask* StartConsumingCodeCacheOnBackground(
781 Isolate* isolate, std::unique_ptr<CachedData> source);
782
783 /**
784 * Compiles a streamed script (bound to current context).
785 *
786 * This can only be called after the streaming has finished
787 * (ScriptStreamingTask has been run). V8 doesn't construct the source string
788 * during streaming, so the embedder needs to pass the full source here.
789 */
791 Local<Context> context, StreamedSource* source,
792 Local<String> full_source_string, const ScriptOrigin& origin);
793
794 /**
795 * Return a version tag for CachedData for the current V8 version & flags.
796 *
797 * This value is meant only for determining whether a previously generated
798 * CachedData instance is still valid; the tag has no other meaing.
799 *
800 * Background: The data carried by CachedData may depend on the exact
801 * V8 version number or current compiler flags. This means that when
802 * persisting CachedData, the embedder must take care to not pass in
803 * data from another V8 version, or the same version with different
804 * features enabled.
805 *
806 * The easiest way to do so is to clear the embedder's cache on any
807 * such change.
808 *
809 * Alternatively, this tag can be stored alongside the cached data and
810 * compared when it is being used.
811 */
812 static uint32_t CachedDataVersionTag();
813
814 /**
815 * Compile an ES module, returning a Module that encapsulates
816 * the compiled code.
817 *
818 * Corresponds to the ParseModule abstract operation in the
819 * ECMAScript specification.
820 */
822 Isolate* isolate, Source* source,
824 NoCacheReason no_cache_reason = kNoCacheNoReason);
825
826 /**
827 * Compiles a streamed module script.
828 *
829 * This can only be called after the streaming has finished
830 * (ScriptStreamingTask has been run). V8 doesn't construct the source string
831 * during streaming, so the embedder needs to pass the full source here.
832 */
834 Local<Context> context, StreamedSource* v8_source,
835 Local<String> full_source_string, const ScriptOrigin& origin);
836
837 /**
838 * Compile a function for a given context. This is equivalent to running
839 *
840 * with (obj) {
841 * return function(args) { ... }
842 * }
843 *
844 * It is possible to specify multiple context extensions (obj in the above
845 * example).
846 */
848 Local<Context> context, Source* source, size_t arguments_count = 0,
849 Local<String> arguments[] = nullptr, size_t context_extension_count = 0,
850 Local<Object> context_extensions[] = nullptr,
852 NoCacheReason no_cache_reason = kNoCacheNoReason);
853
854 /**
855 * Creates and returns code cache for the specified unbound_script.
856 * This will return nullptr if the script cannot be serialized. The
857 * CachedData returned by this function should be owned by the caller.
858 */
860
861 /**
862 * Creates and returns code cache for the specified unbound_module_script.
863 * This will return nullptr if the script cannot be serialized. The
864 * CachedData returned by this function should be owned by the caller.
865 */
867 Local<UnboundModuleScript> unbound_module_script);
868
869 /**
870 * Creates and returns code cache for the specified function that was
871 * previously produced by CompileFunction.
872 * This will return nullptr if the script cannot be serialized. The
873 * CachedData returned by this function should be owned by the caller.
874 */
876
877 private:
878 static V8_WARN_UNUSED_RESULT MaybeLocal<UnboundScript> CompileUnboundInternal(
879 Isolate* isolate, Source* source, CompileOptions options,
880 NoCacheReason no_cache_reason);
881
882 static V8_WARN_UNUSED_RESULT MaybeLocal<Function> CompileFunctionInternal(
883 Local<Context> context, Source* source, size_t arguments_count,
884 Local<String> arguments[], size_t context_extension_count,
885 Local<Object> context_extensions[], CompileOptions options,
886 NoCacheReason no_cache_reason,
887 Local<ScriptOrModule>* script_or_module_out);
888};
889
891 CachedData* data,
892 ConsumeCodeCacheTask* consume_cache_task)
895 resource_line_offset(origin.LineOffset()),
896 resource_column_offset(origin.ColumnOffset()),
897 resource_options(origin.Options()),
902
904 ConsumeCodeCacheTask* consume_cache_task)
908
910 CompileHintCallback callback,
911 void* callback_data)
914 resource_line_offset(origin.LineOffset()),
915 resource_column_offset(origin.ColumnOffset()),
916 resource_options(origin.Options()),
919 compile_hint_callback(callback),
920 compile_hint_callback_data(callback_data) {}
921
923 const {
924 return cached_data.get();
925}
926
928 return resource_options;
929}
930
933 return compilation_details;
934}
935
937#ifdef V8_ENABLE_CHECKS
938 CheckCast(data);
939#endif
940 return reinterpret_cast<ModuleRequest*>(data);
941}
942
944#ifdef V8_ENABLE_CHECKS
945 CheckCast(data);
946#endif
947 return reinterpret_cast<Module*>(data);
948}
949
950} // namespace v8
951
952#endif // INCLUDE_V8_SCRIPT_H_
std::vector< int > GetCompileHints(Isolate *isolate) const
friend class Local
friend class MaybeLocal
int GetColumnNumber()
Definition v8-script.h:115
int GetLineNumber()
Definition v8-script.h:114
Location(int line_number, int column_number)
Definition v8-script.h:117
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Evaluate(Local< Context > context)
bool HasTopLevelAwait() const
std::pair< LocalVector< Module >, LocalVector< Message > > GetStalledTopLevelAwaitMessages(Isolate *isolate)
V8_WARN_UNUSED_RESULT Maybe< bool > InstantiateModule(Local< Context > context, ResolveModuleCallback module_callback, ResolveSourceCallback source_callback=nullptr)
Status GetStatus() const
Local< UnboundModuleScript > GetUnboundModuleScript()
@ kUninstantiated
Definition v8-script.h:182
static Local< Module > CreateSyntheticModule(Isolate *isolate, Local< String > module_name, const MemorySpan< const Local< String > > &export_names, SyntheticModuleEvaluationSteps evaluation_steps)
Local< FixedArray > GetModuleRequests() const
Local< Value > GetModuleNamespace()
Local< Value > GetException() const
bool IsSyntheticModule() const
static V8_INLINE Module * Cast(Data *data)
Definition v8-script.h:943
Location SourceOffsetToLocation(int offset) const
int GetIdentityHash() const
int ScriptId() const
bool IsSourceTextModule() const
V8_WARN_UNUSED_RESULT Maybe< bool > SetSyntheticModuleExport(Isolate *isolate, Local< String > export_name, Local< Value > export_value)
bool IsGraphAsync() const
ModuleImportPhase GetPhase() const
static V8_INLINE ModuleRequest * Cast(Data *data)
Definition v8-script.h:936
Local< FixedArray > GetImportAssertions() const
Definition v8-script.h:159
int GetSourceOffset() const
Local< FixedArray > GetImportAttributes() const
Local< String > GetSpecifier() const
void SourceTextAvailable(Isolate *isolate, Local< String > source_text, const ScriptOrigin &origin)
virtual size_t GetMoreData(const uint8_t **src)=0
V8_INLINE Source(Local< String > source_string, const ScriptOrigin &origin, CompileHintCallback callback, void *callback_data)
Definition v8-script.h:909
V8_INLINE ~Source()=default
V8_INLINE const CompilationDetails & GetCompilationDetails() const
Definition v8-script.h:932
V8_INLINE const CachedData * GetCachedData() const
Definition v8-script.h:922
V8_INLINE Source(Local< String > source_string, CachedData *cached_data=nullptr, ConsumeCodeCacheTask *consume_cache_task=nullptr)
Definition v8-script.h:903
V8_INLINE const ScriptOriginOptions & GetResourceOptions() const
Definition v8-script.h:927
V8_INLINE Source(Local< String > source_string, const ScriptOrigin &origin, CachedData *cached_data=nullptr, ConsumeCodeCacheTask *consume_cache_task=nullptr)
Definition v8-script.h:890
CompilationDetails & compilation_details()
Definition v8-script.h:596
internal::ScriptStreamingData * impl() const
Definition v8-script.h:590
StreamedSource & operator=(const StreamedSource &)=delete
StreamedSource(const StreamedSource &)=delete
StreamedSource(std::unique_ptr< ExternalSourceStream > source_stream, Encoding encoding)
static V8_WARN_UNUSED_RESULT MaybeLocal< Module > CompileModule(Local< Context > context, StreamedSource *v8_source, Local< String > full_source_string, const ScriptOrigin &origin)
static V8_WARN_UNUSED_RESULT MaybeLocal< Function > CompileFunction(Local< Context > context, Source *source, size_t arguments_count=0, Local< String > arguments[]=nullptr, size_t context_extension_count=0, Local< Object > context_extensions[]=nullptr, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
static V8_WARN_UNUSED_RESULT MaybeLocal< Script > Compile(Local< Context > context, StreamedSource *source, Local< String > full_source_string, const ScriptOrigin &origin)
static ConsumeCodeCacheTask * StartConsumingCodeCache(Isolate *isolate, std::unique_ptr< CachedData > source)
@ kNoCacheBecauseDeferredProduceCodeCache
Definition v8-script.h:721
@ kNoCacheBecauseResourceWithNoCacheHandler
Definition v8-script.h:720
static V8_WARN_UNUSED_RESULT MaybeLocal< Script > Compile(Local< Context > context, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
static CachedData * CreateCodeCache(Local< UnboundScript > unbound_script)
static V8_WARN_UNUSED_RESULT MaybeLocal< UnboundScript > CompileUnboundScript(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
static CachedData * CreateCodeCacheForFunction(Local< Function > function)
@ kFollowCompileHintsMagicComment
Definition v8-script.h:679
@ kFollowCompileHintsPerFunctionMagicComment
Definition v8-script.h:680
static uint32_t CachedDataVersionTag()
static V8_WARN_UNUSED_RESULT MaybeLocal< Module > CompileModule(Isolate *isolate, Source *source, CompileOptions options=kNoCompileOptions, NoCacheReason no_cache_reason=kNoCacheNoReason)
static CachedData * CreateCodeCache(Local< UnboundModuleScript > unbound_module_script)
static ScriptStreamingTask * StartStreaming(Isolate *isolate, StreamedSource *source, ScriptType type=ScriptType::kClassic, CompileOptions options=kNoCompileOptions, CompileHintCallback compile_hint_callback=nullptr, void *compile_hint_callback_data=nullptr)
static ConsumeCodeCacheTask * StartConsumingCodeCacheOnBackground(Isolate *isolate, std::unique_ptr< CachedData > source)
static bool CompileOptionsIsValid(CompileOptions compile_options)
Definition v8-script.h:683
Local< UnboundScript > GetUnboundScript()
static V8_WARN_UNUSED_RESULT MaybeLocal< Script > Compile(Local< Context > context, Local< String > source, ScriptOrigin *origin=nullptr)
Local< CompileHintsCollector > GetCompileHintsCollector() const
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Run(Local< Context > context)
std::vector< int > GetProducedCompileHints() const
Local< Value > GetResourceName()
V8_WARN_UNUSED_RESULT MaybeLocal< Value > Run(Local< Context > context, Local< Data > host_defined_options)
Local< Value > GetResourceName()
Local< Data > HostDefinedOptions()
V8_INLINE int ColumnOffset() const
Definition v8-message.h:215
V8_INLINE int LineOffset() const
Definition v8-message.h:213
V8_INLINE ScriptOriginOptions Options() const
Definition v8-message.h:91
Local< Value > GetSourceMappingURL()
Local< Value > GetSourceURL()
static const int kNoScriptId
Definition v8-script.h:91
int GetColumnNumber(int code_pos=0)
Local< Script > BindToCurrentContext()
Local< Value > GetSourceMappingURL()
Local< Value > GetSourceURL()
int GetLineNumber(int code_pos=0)
int GetId() const
Local< Value > GetScriptName()
ScriptType
Definition v8-script.h:397
ModuleImportPhase
CachedData(const CachedData &)=delete
CachedData & operator=(const CachedData &)=delete
CachedData(const uint8_t *data, int length, BufferPolicy buffer_policy=BufferNotOwned)
CompatibilityCheckResult CompatibilityCheck(Isolate *isolate)
static constexpr int64_t kTimeNotMeasured
Definition v8-script.h:484
InMemoryCacheResult in_memory_cache_result
Definition v8-script.h:481
#define V8_EXPORT
Definition v8config.h:860
#define V8_INLINE
Definition v8config.h:513
#define V8_DEPRECATE_SOON(message)
Definition v8config.h:627
#define V8_DEPRECATED(message)
Definition v8config.h:619
#define V8_WARN_UNUSED_RESULT
Definition v8config.h:684