aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-06-06 23:44:40 -0700
committerGravatar GitHub <noreply@github.com> 2023-06-06 23:44:40 -0700
commitbcd67c3455749d28fab8c31c63080c6682202506 (patch)
tree437c733244100cdb5cfc5898a2eb2b34d6fbf6e9 /src/bun.js
parentec71e7afe49d5110f3c9d0eba8e49ea22a549e41 (diff)
downloadbun-bcd67c3455749d28fab8c31c63080c6682202506.tar.gz
bun-bcd67c3455749d28fab8c31c63080c6682202506.tar.zst
bun-bcd67c3455749d28fab8c31c63080c6682202506.zip
Bun.passwordSync -> Bun.password.{method}Sync (#3228)
* Bun.passwordSync -> Bun.password.{method}Sync * Update jsdoc * Updates
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/bun.zig34
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp17
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.h2
3 files changed, 19 insertions, 34 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index 78a7379c2..7e9e3ca30 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -1632,7 +1632,7 @@ pub const Crypto = struct {
return ZigString.fromUTF8(error_message).toErrorInstance(globalThis);
}
- const unknwon_password_algorithm_message = "unknown algorithm, expected one of: \"bcrypt\", \"argon2id\", \"argon2d\", \"argon2i\" (default is \"argon2id\")";
+ const unknown_password_algorithm_message = "unknown algorithm, expected one of: \"bcrypt\", \"argon2id\", \"argon2d\", \"argon2i\" (default is \"argon2id\")";
pub const PasswordObject = struct {
pub const pwhash = std.crypto.pwhash;
@@ -1666,7 +1666,7 @@ pub const Crypto = struct {
const algorithm_string = algorithm_value.getZigString(globalObject);
switch (PasswordObject.Algorithm.label.getWithEql(algorithm_string, JSC.ZigString.eqlComptime) orelse {
- globalObject.throwInvalidArgumentType("hash", "algorithm", unknwon_password_algorithm_message);
+ globalObject.throwInvalidArgumentType("hash", "algorithm", unknown_password_algorithm_message);
return null;
}) {
.bcrypt => {
@@ -1740,7 +1740,7 @@ pub const Crypto = struct {
const algorithm_string = value.getZigString(globalObject);
switch (PasswordObject.Algorithm.label.getWithEql(algorithm_string, JSC.ZigString.eqlComptime) orelse {
- globalObject.throwInvalidArgumentType("hash", "algorithm", unknwon_password_algorithm_message);
+ globalObject.throwInvalidArgumentType("hash", "algorithm", unknown_password_algorithm_message);
return null;
}) {
.bcrypt => {
@@ -1950,23 +1950,27 @@ pub const Crypto = struct {
}
};
- pub export fn JSPasswordObject__create(globalObject: *JSC.JSGlobalObject, sync: bool) JSC.JSValue {
- var object = JSValue.createEmptyObject(globalObject, 2);
+ pub export fn JSPasswordObject__create(globalObject: *JSC.JSGlobalObject) JSC.JSValue {
+ var object = JSValue.createEmptyObject(globalObject, 4);
object.put(
globalObject,
ZigString.static("hash"),
- if (!sync)
- JSC.NewFunction(globalObject, ZigString.static("hash"), 2, JSPasswordObject__hash, false)
- else
- JSC.NewFunction(globalObject, ZigString.static("hash"), 2, JSPasswordObject__hashSync, false),
+ JSC.NewFunction(globalObject, ZigString.static("hash"), 2, JSPasswordObject__hash, false),
+ );
+ object.put(
+ globalObject,
+ ZigString.static("hashSync"),
+ JSC.NewFunction(globalObject, ZigString.static("hashSync"), 2, JSPasswordObject__hashSync, false),
);
object.put(
globalObject,
ZigString.static("verify"),
- if (!sync)
- JSC.NewFunction(globalObject, ZigString.static("verify"), 2, JSPasswordObject__verify, false)
- else
- JSC.NewFunction(globalObject, ZigString.static("verify"), 2, JSPasswordObject__verifySync, false),
+ JSC.NewFunction(globalObject, ZigString.static("verify"), 2, JSPasswordObject__verify, false),
+ );
+ object.put(
+ globalObject,
+ ZigString.static("verifySync"),
+ JSC.NewFunction(globalObject, ZigString.static("verifySync"), 2, JSPasswordObject__verifySync, false),
);
return object;
}
@@ -2333,7 +2337,7 @@ pub const Crypto = struct {
const algorithm_string = arguments[2].getZigString(globalObject);
algorithm = PasswordObject.Algorithm.label.getWithEql(algorithm_string, JSC.ZigString.eqlComptime) orelse {
- globalObject.throwInvalidArgumentType("verify", "algorithm", unknwon_password_algorithm_message);
+ globalObject.throwInvalidArgumentType("verify", "algorithm", unknown_password_algorithm_message);
return JSC.JSValue.undefined;
};
}
@@ -2398,7 +2402,7 @@ pub const Crypto = struct {
const algorithm_string = arguments[2].getZigString(globalObject);
algorithm = PasswordObject.Algorithm.label.getWithEql(algorithm_string, JSC.ZigString.eqlComptime) orelse {
- globalObject.throwInvalidArgumentType("verify", "algorithm", unknwon_password_algorithm_message);
+ globalObject.throwInvalidArgumentType("verify", "algorithm", unknown_password_algorithm_message);
return JSC.JSValue.undefined;
};
}
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index bd9c19133..3e01e2bc7 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -2620,15 +2620,6 @@ void GlobalObject::finishCreation(VM& vm)
init.set(result.toObject(globalObject));
});
- m_lazyPasswordSyncObject.initLater(
- [](const Initializer<JSObject>& init) {
- JSC::VM& vm = init.vm;
- JSC::JSGlobalObject* globalObject = init.owner;
-
- JSValue result = JSValue::decode(JSPasswordObject__create(globalObject, true));
- init.set(result.toObject(globalObject));
- });
-
m_lazyPreloadTestModuleObject.initLater(
[](const Initializer<JSObject>& init) {
JSC::VM& vm = init.vm;
@@ -3556,7 +3547,6 @@ extern "C" void Crypto__randomUUID__put(JSC::JSGlobalObject* globalObject, JSC::
extern "C" void Crypto__getRandomValues__put(JSC::JSGlobalObject* globalObject, JSC::EncodedJSValue value);
DEFINE_BUN_LAZY_GETTER(BUN_LAZY_GETTER_FN_NAME(password), passwordObject)
-DEFINE_BUN_LAZY_GETTER(BUN_LAZY_GETTER_FN_NAME(passwordSync), passwordSyncObject)
// This is not a publicly exposed API currently.
// This is used by the bundler to make Response, Request, FetchEvent,
@@ -3624,12 +3614,6 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm
}
{
- JSC::Identifier identifier = JSC::Identifier::fromString(vm, "passwordSync"_s);
- object->putDirectCustomAccessor(vm, identifier, JSC::CustomGetterSetter::create(vm, BUN_LAZY_GETTER_FN_NAME(passwordSync), nullptr),
- JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontDelete | 0);
- }
-
- {
JSC::Identifier identifier = JSC::Identifier::fromString(vm, "readableStreamToArrayBuffer"_s);
object->putDirectBuiltinFunction(vm, this, identifier, readableStreamReadableStreamToArrayBufferCodeGenerator(vm),
JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0);
@@ -3900,7 +3884,6 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->m_lazyPreloadTestModuleObject.visit(visitor);
thisObject->m_commonJSModuleObjectStructure.visit(visitor);
thisObject->m_lazyPasswordObject.visit(visitor);
- thisObject->m_lazyPasswordSyncObject.visit(visitor);
thisObject->m_commonJSFunctionArgumentsStructure.visit(visitor);
thisObject->m_cachedGlobalObjectStructure.visit(visitor);
thisObject->m_cachedGlobalProxyStructure.visit(visitor);
diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h
index 2363df74d..dbafa1a93 100644
--- a/src/bun.js/bindings/ZigGlobalObject.h
+++ b/src/bun.js/bindings/ZigGlobalObject.h
@@ -264,7 +264,6 @@ public:
Structure* commonJSFunctionArgumentsStructure() { return m_commonJSFunctionArgumentsStructure.getInitializedOnMainThread(this); }
- JSObject* passwordSyncObject() { return m_lazyPasswordSyncObject.getInitializedOnMainThread(this); }
JSObject* passwordObject() { return m_lazyPasswordObject.getInitializedOnMainThread(this); }
JSWeakMap* vmModuleContextMap() { return m_vmModuleContextMap.getInitializedOnMainThread(this); }
@@ -479,7 +478,6 @@ private:
LazyProperty<JSGlobalObject, JSObject> m_lazyRequireCacheObject;
LazyProperty<JSGlobalObject, JSObject> m_lazyTestModuleObject;
LazyProperty<JSGlobalObject, JSObject> m_lazyPreloadTestModuleObject;
- LazyProperty<JSGlobalObject, JSObject> m_lazyPasswordSyncObject;
LazyProperty<JSGlobalObject, JSObject> m_lazyPasswordObject;
LazyProperty<JSGlobalObject, JSFunction> m_bunSleepThenCallback;