#include "root.h" #include "./NodeModuleModule.h" #include "ImportMetaObject.h" #include "JavaScriptCore/JSBoundFunction.h" #include "JavaScriptCore/ObjectConstructor.h" using namespace Zig; using namespace JSC; JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeModuleCreateRequire, (JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) { JSC::VM &vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (callFrame->argumentCount() < 1) { throwTypeError(globalObject, scope, "createRequire() requires at least one argument"_s); return JSC::JSValue::encode(JSC::jsUndefined()); } Zig::ImportMetaObject *importMetaObject = Zig::ImportMetaObject::create( globalObject, callFrame->uncheckedArgument(0)); auto clientData = WebCore::clientData(vm); RETURN_IF_EXCEPTION(scope, {}); if (!importMetaObject) { throwTypeError(globalObject, scope, "Invalid path"_s); return JSC::JSValue::encode(JSC::jsUndefined()); } auto requireFunctionValue = importMetaObject->get( globalObject, clientData->builtinNames().requirePublicName()); RETURN_IF_EXCEPTION(scope, {}); JSC::JSBoundFunction *boundRequireFunction = JSC::JSBoundFunction::create( vm, globalObject, requireFunctionValue.getObject(), importMetaObject, nullptr, 1, jsString(vm, String("require"_s))); RETURN_IF_EXCEPTION(scope, {}); auto resolveFunction = importMetaObject->get( globalObject, clientData->builtinNames().resolveSyncPublicName()); JSC::JSBoundFunction *boundResolveFunction = JSC::JSBoundFunction::create( vm, globalObject, resolveFunction.getObject(), importMetaObject, nullptr, 1, jsString(vm, String("resolve"_s))); boundRequireFunction->putDirect( vm, clientData->builtinNames().resolvePublicName(), boundResolveFunction, JSC::PropertyAttribute::Function | 0); RELEASE_AND_RETURN(scope, JSC::JSValue::encode(boundRequireFunction)); } JSC_DEFINE_HOST_FUNCTION(jsFunctionNodeModulePaths, (JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) { return JSC::JSValue::encode(JSC::JSArray::create( globalObject->vm(), globalObject->arrayStructureForIndexingTypeDuringAllocation( ArrayWithContiguous), 0)); } JSC_DEFINE_HOST_FUNCTION(jsFunctionFindSourceMap, (JSGlobalObject * globalObject, CallFrame *callFrame)) { auto &vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); throwException(globalObject, scope, createError(globalObject, "Not implemented"_s)); return JSValue::encode(jsUndefined()); } JSC_DEFINE_HOST_FUNCTION(jsFunctionSyncBuiltinExports, (JSGlobalObject * globalObject, CallFrame *callFrame)) { return JSValue::encode(jsUndefined()); } JSC_DEFINE_HOST_FUNCTION(jsFunctionSourceMap, (JSGlobalObject * globalObject, CallFrame *callFrame)) { auto &vm = globalObject->vm(); auto scope = DECLARE_THROW_SCOPE(vm); throwException(globalObject, scope, createError(globalObject, "Not implemented"_s)); return JSValue::encode(jsUndefined()); } JSC_DEFINE_HOST_FUNCTION(jsFunctionResolveFileName, (JSC::JSGlobalObject * globalObject, JSC::CallFrame *callFrame)) { JSC::VM &vm = globalObject->vm(); switch (callFrame->argumentCount()) { case 0: { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); // not "requires" because "require" could be confusing JSC::throwTypeError( globalObject, scope, "Module._resolveFileName needs 2+ arguments (a string)"_s); scope.release(); return JSC::JSValue::encode(JSC::JSValue{}); } default: { JSC::JSValue moduleName = callFrame->argument(0); if (moduleName.isUndefinedOrNull()) { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); JSC::throwTypeError(globalObject, scope, "Module._resolveFileName expects a string"_s); scope.release(); return JSC::JSValue::encode(JSC::JSValue{}); } auto result = Bun__resolveSync(globalObject, JSC::JSValue::encode(moduleName), JSValue::encode(callFrame->argument(1))); auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); if (!JSC::JSValue::decode(result).isString()) { JSC::throwException(globalObject, scope, JSC::JSValue::decode(result)); return JSC::JSValue::encode(JSC::JSValue{}); } scope.release(); return result; } } } namespace Zig { void generateNodeModuleModule(JSC::JSGlobalObject *globalObject, JSC::Identifier moduleKey, Vector &exportNames, JSC::MarkedArgumentBuffer &exportValues) { JSC::VM &vm = globalObject->vm(); exportValues.append(JSFunction::create( vm, globalObject, 1, String("createRequire"_s), jsFunctionNodeModuleCreateRequire, ImplementationVisibility::Public)); exportValues.append(JSFunction::create(vm, globalObject, 1, String("paths"_s), jsFunctionNodeModulePaths, ImplementationVisibility::Public)); exportValues.append(JSFunction::create( vm, globalObject, 1, String("findSourceMap"_s), jsFunctionFindSourceMap, ImplementationVisibility::Public)); exportValues.append(JSFunction::create( vm, globalObject, 0, String("syncBuiltinExports"_s), jsFunctionSyncBuiltinExports, ImplementationVisibility::Public)); exportValues.append( JSFunction::create(vm, globalObject, 1, String("SourceMap"_s), jsFunctionSourceMap, ImplementationVisibility::Public, NoIntrinsic, jsFunctionSourceMap, nullptr)); exportNames.append(JSC::Identifier::fromString(vm, "createRequire"_s)); exportNames.append(JSC::Identifier::fromString(vm, "paths"_s)); exportNames.append(JSC::Identifier::fromString(vm, "findSourceMap"_s)); exportNames.append(JSC::Identifier::fromString(vm, "syncBuiltinExports"_s)); exportNames.append(JSC::Identifier::fromString(vm, "SourceMap"_s)); // note: this is not technically correct // it doesn't set process.mainModule exportNames.append(JSC::Identifier::fromString(vm, "_resolveFileName"_s)); exportValues.append(JSFunction::create( vm, globalObject, 3, String("_resolveFileName"_s), jsFunctionResolveFileName, ImplementationVisibility::Public)); exportNames.append(JSC::Identifier::fromString(vm, "_nodeModulePaths"_s)); exportValues.append(JSFunction::create( vm, globalObject, 0, String("_nodeModulePaths"_s), jsFunctionNodeModulePaths, ImplementationVisibility::Public)); exportNames.append(JSC::Identifier::fromString(vm, "_cache"_s)); exportValues.append(JSC::constructEmptyObject(globalObject)); exportNames.append(JSC::Identifier::fromString(vm, "builtinModules"_s)); JSC::JSArray *builtinModules = JSC::JSArray::create( vm, globalObject->arrayStructureForIndexingTypeDuringAllocation( ArrayWithContiguous), 7); builtinModules->putDirectIndex(globalObject, 0, JSC::jsString(vm, String("node:assert"_s))); builtinModules->putDirectIndex(globalObject, 1, JSC::jsString(vm, String("node:buffer"_s))); builtinModules->putDirectIndex(globalObject, 2, JSC::jsString(vm, String("node:events"_s))); builtinModules->putDirectIndex(globalObject, 3, JSC::jsString(vm, String("node:util"_s))); builtinModules->putDirectIndex(globalObject, 4, JSC::jsString(vm, String("node:path"_s))); builtinModules->putDirectIndex(globalObject, 5, JSC::jsString(vm, String("bun:ffi"_s))); builtinModules->putDirectIndex(globalObject, 6, JSC::jsString(vm, String("bun:sqlite"_s))); exportValues.append(builtinModules); } } // namespace Zig on value='jarred/jsc'>jarred/jsc Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/jsx-entity-decoding.jsx (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2022-11-29:scissors:Gravatar Jarred Sumner 5-626/+7
2022-11-29Remove some dead bindings codeGravatar Jarred Sumner 7-1401/+69
2022-11-29import everything from "bun" where possibleGravatar Jarred Sumner 161-739/+621
2022-11-28Make .toInt64 fasterGravatar Jarred Sumner 1-0/+8
2022-11-28Handle when the process already exited immediatelyGravatar Jarred Sumner 3-38/+47
2022-11-28toHaveProperty and tests (#1558)Gravatar Dylan Conway 8-118/+532
* toHaveProperty and tests * emoji tests
2022-11-28Fix failing spawn() and spawnSync() testsGravatar Jarred Sumner 7-143/+317
cc @ThatOneBro
2022-11-28Update README.mdGravatar Jarred Sumner 1-1/+26
2022-11-28Update README.mdGravatar Jarred Sumner 1-5/+5
2022-11-28Add small section about profiling bunGravatar Jarred Sumner 1-0/+171
2022-11-28Fix hanging in FIFO streamsGravatar Jarred Sumner 1-1/+2
2022-11-28[internal] Add debug timerGravatar Jarred Sumner 2-2/+33
2022-11-28Ensure we report errors in controller.closeGravatar Jarred Sumner 1-1/+9
2022-11-28Update JSEnvironmentVariableMap.cppGravatar Jarred Sumner 1-1/+1
2022-11-28Allow overriding node:fsGravatar Jarred Sumner 1-0/+9
2022-11-28Add test for processGravatar Jarred Sumner 1-3/+14
2022-11-28Fix process.env and Bun.env object spreadGravatar Jarred Sumner 8-204/+127
Fixes https://github.com/oven-sh/bun/issues/1512
2022-11-27Fix `console.log(process.env)`Gravatar Jarred Sumner 2-20/+27