aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ZigSourceProvider.h
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 23:21:48 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-22 23:21:48 -0700
commit729d445b6885f69dd2c6355f38707bd42851c791 (patch)
treef87a7c408929ea3f57bbb7ace380cf869da83c0e /src/bun.js/bindings/ZigSourceProvider.h
parent25f820c6bf1d8ec6d444ef579cc036b8c0607b75 (diff)
downloadbun-jarred/rename.tar.gz
bun-jarred/rename.tar.zst
bun-jarred/rename.zip
change the directory structurejarred/rename
Diffstat (limited to 'src/bun.js/bindings/ZigSourceProvider.h')
-rw-r--r--src/bun.js/bindings/ZigSourceProvider.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/bun.js/bindings/ZigSourceProvider.h b/src/bun.js/bindings/ZigSourceProvider.h
new file mode 100644
index 000000000..cd45a0217
--- /dev/null
+++ b/src/bun.js/bindings/ZigSourceProvider.h
@@ -0,0 +1,87 @@
+#include "headers.h"
+#include "root.h"
+
+#pragma once
+
+namespace JSC {
+class Structure;
+class Identifier;
+class SourceCodeKey;
+class SourceProvider;
+} // namespace JSC
+
+#include "JavaScriptCore/CachedBytecode.h"
+#include "JavaScriptCore/JSGlobalObject.h"
+#include "JavaScriptCore/JSTypeInfo.h"
+#include "ZigConsoleClient.h"
+// #include "JavaScriptCore/SourceCodeKey.h"
+#include "JavaScriptCore/SourceProvider.h"
+#include "JavaScriptCore/Structure.h"
+
+namespace Zig {
+
+class SourceProvider final : public JSC::SourceProvider {
+ WTF_MAKE_FAST_ALLOCATED;
+ using Base = JSC::SourceProvider;
+ using BytecodeCacheGenerator = JSC::BytecodeCacheGenerator;
+ using UnlinkedFunctionExecutable = JSC::UnlinkedFunctionExecutable;
+ using CachedBytecode = JSC::CachedBytecode;
+ using UnlinkedFunctionCodeBlock = JSC::UnlinkedFunctionCodeBlock;
+ using SourceCode = JSC::SourceCode;
+ using CodeSpecializationKind = JSC::CodeSpecializationKind;
+ using SourceOrigin = JSC::SourceOrigin;
+
+public:
+ static Ref<SourceProvider> create(ResolvedSource resolvedSource);
+ ~SourceProvider()
+ {
+ freeSourceCode();
+
+ commitCachedBytecode();
+ }
+
+ unsigned hash() const { return m_hash; };
+ StringView source() const { return StringView(m_source.get()); }
+ RefPtr<JSC::CachedBytecode> cachedBytecode()
+ {
+ // if (m_resolvedSource.bytecodecache_fd == 0) {
+ return nullptr;
+ // }
+
+ // return m_cachedBytecode;
+ };
+
+ void updateCache(const UnlinkedFunctionExecutable* executable, const SourceCode&,
+ CodeSpecializationKind kind, const UnlinkedFunctionCodeBlock* codeBlock);
+ void cacheBytecode(const BytecodeCacheGenerator& generator);
+ void commitCachedBytecode();
+ bool isBytecodeCacheEnabled() const;
+ void readOrGenerateByteCodeCache(JSC::VM& vm, const JSC::SourceCode& sourceCode);
+ ResolvedSource m_resolvedSource;
+ int readCache(JSC::VM& vm, const JSC::SourceCode& sourceCode);
+ void freeSourceCode();
+
+private:
+ SourceProvider(ResolvedSource resolvedSource, WTF::StringImpl& sourceImpl,
+ const SourceOrigin& sourceOrigin, WTF::String&& sourceURL,
+ const TextPosition& startPosition, JSC::SourceProviderSourceType sourceType)
+ : Base(sourceOrigin, WTFMove(sourceURL), startPosition, sourceType)
+ , m_source(sourceImpl)
+ {
+
+ m_resolvedSource = resolvedSource;
+
+ m_hash = resolvedSource.hash;
+
+ getHash();
+ }
+
+ unsigned m_hash;
+ unsigned getHash();
+ RefPtr<JSC::CachedBytecode> m_cachedBytecode;
+ Ref<WTF::StringImpl> m_source;
+ bool did_free_source_code = false;
+ // JSC::SourceCodeKey key;
+};
+
+} // namespace Zig \ No newline at end of file