diff options
author | 2022-09-03 03:57:43 -0700 | |
---|---|---|
committer | 2022-09-03 03:57:43 -0700 | |
commit | 0ca42e81f31d31270c44f81d88fff33361817720 (patch) | |
tree | 27e27b32d1850a1fada1a002207e3254cbc597e8 /src/bun.js/modules/ObjectModule.h | |
parent | 8b2d07e82ee6249e0886109585b63429ccf3ab3a (diff) | |
download | bun-0ca42e81f31d31270c44f81d88fff33361817720.tar.gz bun-0ca42e81f31d31270c44f81d88fff33361817720.tar.zst bun-0ca42e81f31d31270c44f81d88fff33361817720.zip |
Plugin API (#1199)
* Plugin API
* Fix the bugs
* Implement `"object"` loader
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/modules/ObjectModule.h')
-rw-r--r-- | src/bun.js/modules/ObjectModule.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/bun.js/modules/ObjectModule.h b/src/bun.js/modules/ObjectModule.h new file mode 100644 index 000000000..42ab4dfa5 --- /dev/null +++ b/src/bun.js/modules/ObjectModule.h @@ -0,0 +1,32 @@ +#include "../bindings/ZigGlobalObject.h" +#include "JavaScriptCore/JSGlobalObject.h" + +namespace Zig { +JSC::SyntheticSourceProvider::SyntheticSourceGenerator +generateObjectModuleSourceCode(JSC::JSGlobalObject *globalObject, + JSC::JSObject *object) { + JSC::VM &vm = globalObject->vm(); + + return [strongObject = JSC::Strong<JSC::JSObject>(vm, object)]( + JSC::JSGlobalObject *lexicalGlobalObject, + JSC::Identifier moduleKey, Vector<JSC::Identifier, 4> &exportNames, + JSC::MarkedArgumentBuffer &exportValues) -> void { + JSC::VM &vm = lexicalGlobalObject->vm(); + GlobalObject *globalObject = + reinterpret_cast<GlobalObject *>(lexicalGlobalObject); + JSC::JSObject *object = strongObject.get(); + + PropertyNameArray properties(vm, PropertyNameMode::Strings, + PrivateSymbolMode::Exclude); + object->getPropertyNames(globalObject, properties, + DontEnumPropertiesMode::Exclude); + + for (auto &entry : properties) { + exportNames.append(entry); + exportValues.append(object->get(globalObject, entry)); + } + strongObject.clear(); + }; +} + +} // namespace Zig
\ No newline at end of file |