diff options
author | 2023-07-24 19:32:04 -0700 | |
---|---|---|
committer | 2023-07-24 19:32:04 -0700 | |
commit | 8a0152e1290658d8167609cb23a7d19817ad4285 (patch) | |
tree | 3ec808e103ed2c360a038c2a22c6b7161bd4adb7 /src/bun.js/bindings/CommonJSModuleRecord.h | |
parent | 1f1d0bfcfbc839cad76c9bc2d644bfa8bd299a1a (diff) | |
download | bun-8a0152e1290658d8167609cb23a7d19817ad4285.tar.gz bun-8a0152e1290658d8167609cb23a7d19817ad4285.tar.zst bun-8a0152e1290658d8167609cb23a7d19817ad4285.zip |
Merge import.meta.require and require to be the same thing (#3732)
* Merge import.meta.require and require to be the same thing
* support `require` and BunPlugin (runtime plugin)
* plugins
* unused code
* revert launch.json
Diffstat (limited to 'src/bun.js/bindings/CommonJSModuleRecord.h')
-rw-r--r-- | src/bun.js/bindings/CommonJSModuleRecord.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/bun.js/bindings/CommonJSModuleRecord.h b/src/bun.js/bindings/CommonJSModuleRecord.h index 15792f9da..20941f454 100644 --- a/src/bun.js/bindings/CommonJSModuleRecord.h +++ b/src/bun.js/bindings/CommonJSModuleRecord.h @@ -39,6 +39,7 @@ public: bool evaluate(Zig::GlobalObject* globalObject, const WTF::String& sourceURL, ResolvedSource resolvedSource); bool evaluate(Zig::GlobalObject* globalObject, const WTF::String& key, const SyntheticSourceProvider::SyntheticSourceGenerator& generator); + bool evaluate(Zig::GlobalObject* globalObject, const WTF::String& key, JSSourceCode* sourceCode); static JSCommonJSModule* create(JSC::VM& vm, JSC::Structure* structure, JSC::JSString* id, @@ -56,6 +57,8 @@ public: const WTF::String& key, ResolvedSource resolvedSource); + static JSObject* createBoundRequireFunction(VM& vm, JSGlobalObject* lexicalGlobalObject, const WTF::String& pathString); + void toSyntheticSource(JSC::JSGlobalObject* globalObject, JSC::Identifier moduleKey, Vector<JSC::Identifier, 4>& exportNames, @@ -95,4 +98,50 @@ std::optional<JSC::SourceCode> createCommonJSModule( Zig::GlobalObject* globalObject, ResolvedSource source); +class RequireResolveFunctionPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + static RequireResolveFunctionPrototype* create(JSC::JSGlobalObject* globalObject); + + DECLARE_INFO; + + RequireResolveFunctionPrototype( + JSC::VM& vm, + JSC::Structure* structure) + : Base(vm, structure) + { + } + + template<typename CellType, JSC::SubspaceAccess> + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + + void finishCreation(JSC::VM& vm); +}; + +class RequireFunctionPrototype final : public JSC::JSNonFinalObject { +public: + using Base = JSC::JSNonFinalObject; + static RequireFunctionPrototype* create(JSC::JSGlobalObject* globalObject); + + RequireFunctionPrototype( + JSC::VM& vm, + JSC::Structure* structure) + : Base(vm, structure) + { + } + + template<typename CellType, JSC::SubspaceAccess> + static JSC::GCClient::IsoSubspace* subspaceFor(JSC::VM& vm) + { + return &vm.plainObjectSpace(); + } + + DECLARE_INFO; + + void finishCreation(JSC::VM& vm); +}; + } // namespace Bun |