diff options
Diffstat (limited to 'src/bun.js/bindings')
-rw-r--r-- | src/bun.js/bindings/ImportMetaObject.cpp | 58 | ||||
-rw-r--r-- | src/bun.js/bindings/bindings.cpp | 13 |
2 files changed, 44 insertions, 27 deletions
diff --git a/src/bun.js/bindings/ImportMetaObject.cpp b/src/bun.js/bindings/ImportMetaObject.cpp index c53235824..4160102a5 100644 --- a/src/bun.js/bindings/ImportMetaObject.cpp +++ b/src/bun.js/bindings/ImportMetaObject.cpp @@ -457,14 +457,20 @@ void ImportMetaObject::finishCreation(VM& vm) ImportMetaObject* meta = jsCast<ImportMetaObject*>(init.owner); WTF::URL url = meta->url.startsWith('/') ? WTF::URL::fileURLWithFileSystemPath(meta->url) : WTF::URL(meta->url); - WTF::StringView path; - if (url.protocolIs("file"_s)) { - path = url.fileSystemPath(); + WTF::String path; + + if (url.isValid()) { + + if (url.protocolIs("file"_s)) { + path = url.fileSystemPath(); + } else { + path = url.path().toString(); + } } else { - path = url.path(); + path = meta->url; } - JSFunction* value = jsCast<JSFunction*>(Bun::JSCommonJSModule::createBoundRequireFunction(init.vm, meta->globalObject(), path.toString())); + JSFunction* value = jsCast<JSFunction*>(Bun::JSCommonJSModule::createBoundRequireFunction(init.vm, meta->globalObject(), path)); init.set(value); }); this->urlProperty.initLater([](const JSC::LazyProperty<JSC::JSObject, JSC::JSString>::Initializer& init) { @@ -477,12 +483,14 @@ void ImportMetaObject::finishCreation(VM& vm) ImportMetaObject* meta = jsCast<ImportMetaObject*>(init.owner); WTF::URL url = meta->url.startsWith('/') ? WTF::URL::fileURLWithFileSystemPath(meta->url) : WTF::URL(meta->url); - WTF::StringView dirname; + WTF::String dirname; - if (url.protocolIs("file"_s)) { - dirname = url.fileSystemPath(); - } else { - dirname = url.path(); + if (url.isValid()) { + if (url.protocolIs("file"_s)) { + dirname = url.fileSystemPath(); + } else { + dirname = url.path().toString(); + } } if (dirname.endsWith("/"_s)) { @@ -491,20 +499,25 @@ void ImportMetaObject::finishCreation(VM& vm) dirname = dirname.substring(0, dirname.reverseFind('/')); } - init.set(jsString(init.vm, dirname.toString())); + init.set(jsString(init.vm, dirname)); }); this->fileProperty.initLater([](const JSC::LazyProperty<JSC::JSObject, JSC::JSString>::Initializer& init) { ImportMetaObject* meta = jsCast<ImportMetaObject*>(init.owner); WTF::URL url = meta->url.startsWith('/') ? WTF::URL::fileURLWithFileSystemPath(meta->url) : WTF::URL(meta->url); - WTF::StringView path; - if (url.protocolIs("file"_s)) { - path = url.fileSystemPath(); + WTF::String path; + + if (!url.isValid()) { + path = meta->url; } else { - path = url.path(); + if (url.protocolIs("file"_s)) { + path = url.fileSystemPath(); + } else { + path = url.path().toString(); + } } - WTF::StringView filename; + WTF::String filename; if (path.endsWith("/"_s)) { filename = path.substring(path.reverseFind('/', path.length() - 2) + 1); @@ -512,21 +525,20 @@ void ImportMetaObject::finishCreation(VM& vm) filename = path.substring(path.reverseFind('/') + 1); } - init.set(jsString(init.vm, filename.toString())); + init.set(jsString(init.vm, filename)); }); this->pathProperty.initLater([](const JSC::LazyProperty<JSC::JSObject, JSC::JSString>::Initializer& init) { ImportMetaObject* meta = jsCast<ImportMetaObject*>(init.owner); WTF::URL url = meta->url.startsWith('/') ? WTF::URL::fileURLWithFileSystemPath(meta->url) : WTF::URL(meta->url); - WTF::StringView path; - if (url.protocolIs("file"_s)) { - path = url.fileSystemPath(); + if (!url.isValid()) { + init.set(jsString(init.vm, meta->url)); + } else if (url.protocolIs("file"_s)) { + init.set(jsString(init.vm, url.fileSystemPath())); } else { - path = url.path(); + init.set(jsString(init.vm, url.path())); } - - init.set(jsString(init.vm, path.toString())); }); } diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index 6413e0470..e46982aad 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -3144,11 +3144,16 @@ JSC__JSValue JSC__JSValue__getIfPropertyExistsImpl(JSC__JSValue JSValue0, const unsigned char* arg1, uint32_t arg2) { + JSValue value = JSC::JSValue::decode(JSValue0); + if (UNLIKELY(!value.isObject())) + return JSValue::encode({}); + JSC::VM& vm = globalObject->vm(); - JSC::JSObject* object = JSC::JSValue::decode(JSValue0).asCell()->getObject(); - auto propertyName = JSC::PropertyName( - JSC::Identifier::fromString(vm, reinterpret_cast<const LChar*>(arg1), (int)arg2)); - return JSC::JSValue::encode(object->getIfPropertyExists(globalObject, propertyName)); + JSC::JSObject* object = value.getObject(); + auto identifier = JSC::Identifier::fromString(vm, String(StringImpl::createWithoutCopying(arg1, arg2))); + auto property = JSC::PropertyName(identifier); + + return JSC::JSValue::encode(object->getIfPropertyExists(globalObject, property)); } JSC__JSValue JSC__JSValue__getIfPropertyExistsFromPath(JSC__JSValue JSValue0, JSC__JSGlobalObject* globalObject, JSC__JSValue arg1) |