aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/NodeVMScript.h
diff options
context:
space:
mode:
authorGravatar Silver <14016168+silversquirl@users.noreply.github.com> 2023-05-19 00:45:18 +0100
committerGravatar GitHub <noreply@github.com> 2023-05-18 16:45:18 -0700
commitac64eb420d6ce29ecca97100b7c64afd63afb26d (patch)
tree96b0d7cd328c037a4d6a9314aafca7bdd64b1466 /src/bun.js/bindings/NodeVMScript.h
parentb76974a2a8a794db41b72e174b86d8536793f8e6 (diff)
downloadbun-ac64eb420d6ce29ecca97100b7c64afd63afb26d.tar.gz
bun-ac64eb420d6ce29ecca97100b7c64afd63afb26d.tar.zst
bun-ac64eb420d6ce29ecca97100b7c64afd63afb26d.zip
Implement `node:vm` (#2785)
* feat: begin implementing node:vm Script object * refactor: clean up and address review comments * refactor: rename Script to VMModuleScript * fix: expose VMModuleScript.prototype also oops I forgot to commit the new files last time * feat(vm): Implement contexts and scripts * feat(vm): implement globalThis * feat(vm): expose node:vm module with global helper functions * refactor(vm): rename VMModuleScript to NodeVMScript * feat: implement script options * doc: add TODOs for runIn*Context options
Diffstat (limited to 'src/bun.js/bindings/NodeVMScript.h')
-rw-r--r--src/bun.js/bindings/NodeVMScript.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/bun.js/bindings/NodeVMScript.h b/src/bun.js/bindings/NodeVMScript.h
new file mode 100644
index 000000000..09878e533
--- /dev/null
+++ b/src/bun.js/bindings/NodeVMScript.h
@@ -0,0 +1,79 @@
+#pragma once
+
+#include "root.h"
+#include "ZigGlobalObject.h"
+
+#include "JavaScriptCore/JSFunction.h"
+#include "JavaScriptCore/VM.h"
+
+#include "headers-handwritten.h"
+#include "BunClientData.h"
+#include "JavaScriptCore/CallFrame.h"
+
+namespace WebCore {
+
+class NodeVMScriptConstructor final : public JSC::InternalFunction {
+public:
+ using Base = JSC::InternalFunction;
+
+ static NodeVMScriptConstructor* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::JSObject* prototype);
+
+ DECLARE_EXPORT_INFO;
+
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::InternalFunctionType, Base::StructureFlags), info());
+ }
+
+private:
+ NodeVMScriptConstructor(JSC::VM& vm, JSC::Structure* structure);
+
+ void finishCreation(JSC::VM&, JSC::JSObject* prototype);
+};
+STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(NodeVMScriptConstructor, InternalFunction);
+
+class NodeVMScript final : public JSC::JSDestructibleObject {
+public:
+ using Base = JSC::JSDestructibleObject;
+
+ static NodeVMScript* create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::Structure* structure, JSC::SourceCode source);
+
+ DECLARE_EXPORT_INFO;
+ template<typename, JSC::SubspaceAccess mode> static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm)
+ {
+ if constexpr (mode == JSC::SubspaceAccess::Concurrently)
+ return nullptr;
+ return WebCore::subspaceForImpl<NodeVMScript, WebCore::UseCustomHeapCellType::No>(
+ vm,
+ [](auto& spaces) { return spaces.m_clientSubspaceForNodeVMScript.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_clientSubspaceForNodeVMScript = std::forward<decltype(space)>(space); },
+ [](auto& spaces) { return spaces.m_subspaceForNodeVMScript.get(); },
+ [](auto& spaces, auto&& space) { spaces.m_subspaceForNodeVMScript = std::forward<decltype(space)>(space); });
+ }
+
+ static void destroy(JSC::JSCell*);
+ static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
+ {
+ return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+ }
+
+ static JSObject* createPrototype(VM& vm, JSGlobalObject* globalObject);
+
+ const JSC::SourceCode& source() const { return m_source; }
+
+private:
+ JSC::SourceCode m_source;
+
+ NodeVMScript(JSC::VM& vm, JSC::Structure* structure, JSC::SourceCode source)
+ : Base(vm, structure)
+ , m_source(source)
+ {
+ }
+
+ void finishCreation(JSC::VM&);
+};
+
+JSC_DECLARE_HOST_FUNCTION(vmModule_createContext);
+JSC_DECLARE_HOST_FUNCTION(vmModule_isContext);
+
+}