#include "root.h" #include "helpers.h" #include "ZigSourceProvider.h" #include "JavaScriptCore/BytecodeCacheError.h" #include "JavaScriptCore/Completion.h" #include "wtf/Scope.h" #include "wtf/text/StringHash.h" #include extern "C" void RefString__free(void*, void*, unsigned); namespace Zig { using Base = JSC::SourceProvider; using BytecodeCacheGenerator = JSC::BytecodeCacheGenerator; using UnlinkedFunctionExecutable = JSC::UnlinkedFunctionExecutable; using CachedBytecode = JSC::CachedBytecode; using UnlinkedFunctionCodeBlock = JSC::UnlinkedFunctionCodeBlock; using SourceCode = JSC::SourceCode; using CodeSpecializationKind = JSC::CodeSpecializationKind; using SourceOrigin = JSC::SourceOrigin; using String = WTF::String; using SourceProviderSourceType = JSC::SourceProviderSourceType; Ref SourceProvider::create(ResolvedSource resolvedSource) { void* allocator = resolvedSource.allocator; JSC::SourceProviderSourceType sourceType = JSC::SourceProviderSourceType::Module; // // JSC owns the memory // if (resolvedSource.hash == 1) { // return adoptRef(*new SourceProvider( // resolvedSource, WTF::StringImpl::create(resolvedSource.source_code.ptr, resolvedSource.source_code.len), // JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))), // toStringNotConst(resolvedSource.source_url).isolatedCopy(), TextPosition(), // sourceType)); // } if (allocator) { Ref stringImpl_ = WTF::ExternalStringImpl::create( resolvedSource.source_code.ptr, resolvedSource.source_code.len, allocator, RefString__free); return adoptRef(*new SourceProvider( resolvedSource, stringImpl_, JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))), toStringNotConst(resolvedSource.source_url), TextPosition(), sourceType)); } else { Ref stringImpl_ = WTF::ExternalStringImpl::createStatic( resolvedSource.source_code.ptr, resolvedSource.source_code.len); return adoptRef(*new SourceProvider( resolvedSource, stringImpl_, JSC::SourceOrigin(WTF::URL::fileURLWithFileSystemPath(toString(resolvedSource.source_url))), toStringNotConst(resolvedSource.source_url), TextPosition(), sourceType)); } } unsigned SourceProvider::getHash() { if (m_hash) { return m_hash; } m_hash = WTF::StringHash::hash(m_source.get()); return m_hash; } void SourceProvider::freeSourceCode() { if (did_free_source_code) { return; } did_free_source_code = true; if (m_resolvedSource.allocator != 0) { // // WTF::ExternalStringImpl::destroy(m_source.ptr()); this->m_source = WTF::StringImpl::empty()->isolatedCopy(); this->m_hash = 0; m_resolvedSource.allocator = 0; } // if (m_resolvedSource.allocator != 0) { // ZigString__free(m_resolvedSource.source_code.ptr, m_resolvedSource.source_code.len, // m_resolvedSource.allocator); // } } void SourceProvider::updateCache(const UnlinkedFunctionExecutable* executable, const SourceCode&, CodeSpecializationKind kind, const UnlinkedFunctionCodeBlock* codeBlock) { // if (!m_resolvedSource.bytecodecache_fd || !m_cachedBytecode) return; JSC::BytecodeCacheError error; RefPtr cachedBytecode = JSC::encodeFunctionCodeBlock(executable->vm(), codeBlock, error); if (cachedBytecode && !error.isValid()) m_cachedBytecode->addFunctionUpdate(executable, kind, *cachedBytecode); } void SourceProvider::cacheBytecode(const BytecodeCacheGenerator& generator) { // if (!m_resolvedSource.bytecodecache_fd) return; if (!m_cachedBytecode) m_cachedBytecode = JSC::CachedBytecode::create(); auto update = generator(); if (update) m_cachedBytecode->addGlobalUpdate(*update); } void SourceProvider::commitCachedBytecode() { // if (!m_resolvedSource.bytecodecache_fd || !m_cachedBytecode || !m_cachedBytecode->hasUpdates()) return; // auto clearBytecode = WTF::makeScopeExit([&] { m_cachedBytecode = nullptr; }); // const auto fd = m_resolvedSource.bytecodecache_fd; // auto fileSize = FileSystem::fileSize(fd); // if (!fileSize) // return; // size_t cacheFileSize; // if (!WTF::convertSafely(*fileSize, cacheFileSize) || cacheFileSize != m_cachedBytecode->size()) { // // The bytecode cache has already been updated // return; // } // if (!FileSystem::truncateFile(fd, m_cachedBytecode->sizeForUpdate())) // return; // m_cachedBytecode->commitUpdates([&](off_t offset, const void* data, size_t size) { // long long result = FileSystem::seekFile(fd, offset, FileSystem::FileSeekOrigin::Beginning); // ASSERT_UNUSED(result, result != -1); // size_t bytesWritten = static_cast(FileSystem::writeToFile(fd, data, size)); // ASSERT_UNUSED(bytesWritten, bytesWritten == size); // }); } bool SourceProvider::isBytecodeCacheEnabled() const { // return m_resolvedSource.bytecodecache_fd > 0; return false; } void SourceProvider::readOrGenerateByteCodeCache(JSC::VM& vm, const JSC::SourceCode& sourceCode) { // auto status = this->readCache(vm, sourceCode); // switch (status) { // case -1: { // m_resolvedSource.bytecodecache_fd = 0; // break; // } // case 0: { // JSC::BytecodeCacheError err; // m_cachedBytecode = JSC::generateModuleBytecode(vm, sourceCode, m_resolvedSource.bytecodecache_fd, err); // if (err.isValid()) { // m_resolvedSource.bytecodecache_fd = 0; // m_cachedBytecode = JSC::CachedBytecode::create(); // } // } // // TODO: read the bytecode into a JSC::SourceCode object here // case 1: { // } // } } int SourceProvider::readCache(JSC::VM& vm, const JSC::SourceCode& sourceCode) { return -1; // if (m_resolvedSource.bytecodecache_fd == 0) // return -1; // if (!FileSystem::isHandleValid(m_resolvedSource.bytecodecache_fd)) // return -1; // const auto fd = m_resolvedSource.bytecodecache_fd; // bool success; // FileSystem::MappedFileData mappedFile(fd, FileSystem::MappedFileMode::Shared, success); // if (!success) // return -1; // const uint8_t* fileData = reinterpret_cast(mappedFile.data()); // unsigned fileTotalSize = mappedFile.size(); // if (fileTotalSize == 0) // return 0; // Ref cachedBytecode = JSC::CachedBytecode::create(WTFMove(mappedFile)); // // auto key = JSC::sourceCodeKeyForSerializedModule(vm, sourceCode); // // if (isCachedBytecodeStillValid(vm, cachedBytecode.copyRef(), key, // // JSC::SourceCodeType::ModuleType)) { // m_cachedBytecode = WTFMove(cachedBytecode); // return 1; // } else { // FileSystem::truncateFile(fd, 0); // return 0; // } } }; // namespace Zigster-ordered-properties'>jarred/faster-ordered-properties Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Expand)AuthorFilesLines
2022-07-23feat: add .PHONY on makefile targets (#847)Gravatar darker 1-19/+113
2022-07-22[bun install] Fix issue with URL path when sending requestGravatar Jarred Sumner 1-1/+55
2022-07-22Fix missing function bugbun-v0.1.5Gravatar Jarred Sumner 1-0/+1
2022-07-22[bun wiptest] This test does not seem to run?Gravatar Jarred Sumner 1-2/+2
2022-07-22`bun install` use custom BUN_CONFIG_REGISTRY port (#823)Gravatar SheetJSDev 1-1/+1
2022-07-22[docker] wipGravatar Jarred Sumner 3-13/+15
2022-07-22[docker] wipGravatar Jarred Sumner 1-2/+2
2022-07-22[docker] Use gcrGravatar Jarred Sumner 1-7/+21
2022-07-22[bun dev] Add flag to force hmrGravatar Jarred Sumner 1-3/+3
2022-07-22Fix link command on macOSGravatar Jarred Sumner 1-1/+1
2022-07-22[bun upgrade] Fix version display name for canary buildGravatar Jarred Sumner 1-1/+34
2022-07-22[bun upgrade] Fix name used in temporary dir for canary buildsGravatar Jarred Sumner 2-6/+26
2022-07-22WIP fix workflow runGravatar Jarred Sumner 1-1/+1
2022-07-22ClarifyGravatar Jarred Sumner 1-1/+1
2022-07-22Mention WSL version requirementGravatar Jarred Sumner 1-0/+2
2022-07-22Only run canary release on push to mainGravatar Jarred Sumner 1-4/+1
2022-07-22[bun upgrade] Implement `--canary` and `BUN_CANARY=1`Gravatar Jarred Sumner 3-20/+113
2022-07-22Fix mistake in Next.js Example README.Gravatar Aaditey Nair 1-1/+1
2022-07-22Update WebKitGravatar Jarred Sumner 1-0/+0
2022-07-22Workaround submodules issueGravatar Jarred Sumner 1-0/+4
2022-07-22Delete plus100-napiGravatar Jarred Sumner 1-0/+0
2022-07-22Rename linux amd64 -> linux x64Gravatar Jarred Sumner 1-18/+18
2022-07-22Mark as executableGravatar Jarred Sumner 4-11/+33
2022-07-22fix: remove suffix arg for mktemp compatibility (#825)Gravatar Connor Lurring 5-5/+5
2022-07-22Canary builds (Linux) (#824)canaryGravatar Jarred Sumner 12-220/+334
2022-07-21Separate Dockerfile for devcontainerGravatar Jarred Sumner 2-1/+100
2022-07-21BumpGravatar Jarred Sumner 1-1/+1
2022-07-21Redo the dockerfileGravatar Jarred SUmner 5-222/+203
2022-07-21docs(templates): Update README.md (#783)Gravatar Sakib Hasan 1-0/+8
2022-07-20chore(vscode): set tab size and tab format (#810)Gravatar Carter Snook 1-1/+2
2022-07-20feat(node/fs): implement more stat methods (#807)Gravatar Carter Snook 3-5/+108
2022-07-20doc: added an helper for the huge MakefileGravatar sanix-darker 1-6/+10
2022-07-20fix install script colorsGravatar Alexander 1-4/+6
2022-07-19Allow blankGravatar Jarred Sumner 1-1/+1
2022-07-19fix(api): stop double-free of prop array (#793)Gravatar Carter Snook 2-8/+6
2022-07-19refactor(installer): renovate install script (#745)Gravatar Wallunen 1-122/+162