Repository navigation
Expand file tree
/
Copy pathScriptStore.h
More file actions
79 lines (66 loc) · 3.61 KB
/
Copy pathScriptStore.h
File metadata and controls
79 lines (66 loc) · 3.61 KB
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
79
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include <jsi/jsi.h>
#include <memory>
namespace facebook {
namespace jsi {
// Integer type as it's persist friendly.
using ScriptVersion_t = uint64_t; // It should be std::optional<uint64_t> once we have c++17 available everywhere. Until
// then, 0 implies versioning not available.
using JSRuntimeVersion_t = uint64_t; // 0 implies version can't be computed. We assert whenever that happens.
struct VersionedBuffer {
std::shared_ptr<const facebook::jsi::Buffer> buffer;
ScriptVersion_t version;
};
struct ScriptSignature {
std::string url;
ScriptVersion_t version;
};
struct JSRuntimeSignature {
std::string runtimeName; // e.g. Chakra, V8
JSRuntimeVersion_t version;
};
// Most JSI::Runtime implementation offer some form of prepared JavaScript which offers better performance
// characteristics when loading comparing to plain JavaScript. Embedders can provide an instance of this interface
// (through JSI::Runtime implementation's factory method), to enable persistance of the prepared script and retrieval on
// subsequent evaluation of a script.
struct PreparedScriptStore {
virtual ~PreparedScriptStore() = default;
// Try to retrieve the prepared javascript for a given combination of script & runtime.
// scriptSignature : Javascript url and version
// RuntimeSignature : Javascript engine type and version
// prepareTag : Custom tag to uniquely identify JS engine specific preparation schemes. It is usually useful while
// experimentation and can be null. It is possible that no prepared script is available for a given script & runtime
// signature. This method should null if so
virtual std::shared_ptr<const facebook::jsi::Buffer> tryGetPreparedScript(
const ScriptSignature &scriptSignature,
const JSRuntimeSignature &runtimeSignature,
const char *prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache.
) noexcept = 0;
// Persist the prepared javascript for a given combination of script & runtime.
// scriptSignature : Javascript url and version
// RuntimeSignature : Javascript engine type and version
// prepareTag : Custom tag to uniquely identify JS engine specific preparation schemes. It is usually useful while
// experimentation and can be null. It is possible that no prepared script is available for a given script & runtime
// signature. This method should null if so Any failure in persistance should be identified during the subsequent
// retrieval through the integrity mechanism which must be put into the storage.
virtual void persistPreparedScript(
std::shared_ptr<const facebook::jsi::Buffer> preparedScript,
const ScriptSignature &scriptMetadata,
const JSRuntimeSignature &runtimeMetadata,
const char *prepareTag // Optional tag. For e.g. eagerly evaluated vs lazy cache.
) noexcept = 0;
};
// JSI::Runtime implementation must be provided an instance on this interface to enable version sensitive capabilities
// such as usage of pre-prepared javascript script. Alternatively, this entity can be used to directly provide the
// Javascript buffer and rich metadata to the JSI::Runtime instance.
struct ScriptStore {
virtual ~ScriptStore() = default;
// Return the Javascript buffer and version corresponding to a given url.
virtual VersionedBuffer getVersionedScript(const std::string &url) noexcept = 0;
// Return the version of the Javascript buffer corresponding to a given url.
virtual ScriptVersion_t getScriptVersion(const std::string &url) noexcept = 0;
};
} // namespace jsi
} // namespace facebook