Skip to content

Commit

Permalink
add BunTranspiledModule and external Bun__analyzeTranspiledModule
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgithub committed Dec 14, 2024
1 parent 58549dd commit 5b6aa34
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Source/JavaScriptCore/parser/SourceProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class UnlinkedFunctionCodeBlock;
JSON,
Synthetic,
ImportMap,
#if USE(BUN_JSC_ADDITIONS)
BunTranspiledModule,
#endif
};

using BytecodeCacheGenerator = Function<RefPtr<CachedBytecode>()>;
Expand Down
20 changes: 20 additions & 0 deletions Source/JavaScriptCore/runtime/JSModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,19 @@ JSValue JSModuleLoader::evaluateNonVirtual(JSGlobalObject* globalObject, JSValue
return jsUndefined();
}


#if USE(BUN_JSC_ADDITIONS)
extern "C" __attribute__((weak)) EncodedJSValue Bun__analyzeTranspiledModule(JSGlobalObject* globalObject, const Identifier& moduleKey, const SourceCode& sourceCode, JSInternalPromise* promise) {
(void)globalObject;
(void)moduleKey;
(void)sourceCode;
(void)promise;

promise->reject(globalObject, createError(globalObject, makeString("Bun__analyzeTranspiledModule is not implemented"_s)));
return JSValue::encode(promise);
}
#endif

JSModuleNamespaceObject* JSModuleLoader::getModuleNamespaceObject(JSGlobalObject* globalObject, JSValue moduleRecordValue)
{
VM& vm = globalObject->vm();
Expand Down Expand Up @@ -375,6 +388,13 @@ JSC_DEFINE_HOST_FUNCTION(moduleLoaderParseModule, (JSGlobalObject* globalObject,
promise->fulfillWithNonPromise(globalObject, moduleRecord);
return JSValue::encode(promise);
}
#if USE(BUN_JSC_ADDITIONS)
case SourceProviderSourceType::BunTranspiledModule: {
EncodedJSValue result = Bun__analyzeTranspiledModule(globalObject, moduleKey, sourceCode, promise);
scope.release();
return result;
}
#endif
default: {
break;
}
Expand Down
3 changes: 2 additions & 1 deletion Source/JavaScriptCore/runtime/ModuleProgramExecutable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const ClassInfo ModuleProgramExecutable::s_info = { "ModuleProgramExecutable"_s,
ModuleProgramExecutable::ModuleProgramExecutable(JSGlobalObject* globalObject, const SourceCode& source)
: Base(globalObject->vm().moduleProgramExecutableStructure.get(), globalObject->vm(), source, StrictModeLexicallyScopedFeature, DerivedContextType::None, false, false, EvalContextType::None, NoIntrinsic)
{
ASSERT(source.provider()->sourceType() == SourceProviderSourceType::Module);
SourceProviderSourceType sourceType = source.provider()->sourceType();
ASSERT(sourceType == SourceProviderSourceType::Module || sourceType == SourceProviderSourceType::BunTranspiledModule);
VM& vm = globalObject->vm();
if (vm.typeProfiler() || vm.controlFlowProfiler())
vm.functionHasExecutedCache()->insertUnexecutedRange(sourceID(), typeProfilingStartOffset(), typeProfilingEndOffset());
Expand Down

0 comments on commit 5b6aa34

Please sign in to comment.