diff options
author | 2022-06-07 22:41:27 -0700 | |
---|---|---|
committer | 2022-06-07 22:41:27 -0700 | |
commit | cdd1a2bdc09105e9be0947c8c7990b1a7c737611 (patch) | |
tree | a0c696a8ee930d0029f681c2913aa1a5c30d023f /src | |
parent | 43de33afc7fcc4cab25f578566e225ba9e4d4258 (diff) | |
download | bun-cdd1a2bdc09105e9be0947c8c7990b1a7c737611.tar.gz bun-cdd1a2bdc09105e9be0947c8c7990b1a7c737611.tar.zst bun-cdd1a2bdc09105e9be0947c8c7990b1a7c737611.zip |
Implement `hashCode`
Diffstat (limited to 'src')
-rw-r--r-- | src/javascript/jsc/bindings/ZigGlobalObject.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/javascript/jsc/bindings/ZigGlobalObject.cpp b/src/javascript/jsc/bindings/ZigGlobalObject.cpp index 7d745b896..3282370bd 100644 --- a/src/javascript/jsc/bindings/ZigGlobalObject.cpp +++ b/src/javascript/jsc/bindings/ZigGlobalObject.cpp @@ -137,7 +137,6 @@ using JSBuffer = WebCore::JSBuffer; #include "ReadableStream.h" // #include <iostream> - static bool has_loaded_jsc = false; extern "C" void JSCInitialize() @@ -787,6 +786,21 @@ static JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolve, } } +static JSC_DECLARE_HOST_FUNCTION(functionHashCode); + +static JSC_DEFINE_HOST_FUNCTION(functionHashCode, + (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) +{ + JSC::JSValue stringToHash = callFrame->argument(0); + JSC::JSString* str = stringToHash.toStringOrNull(globalObject); + if (!str) { + return JSC::JSValue::encode(jsNumber(0)); + } + + auto view = str->value(globalObject); + return JSC::JSValue::encode(jsNumber(view.hash())); +} + static JSC_DECLARE_HOST_FUNCTION(functionImportMeta__resolveSync); static JSC_DEFINE_HOST_FUNCTION(functionImportMeta__resolveSync, @@ -1764,10 +1778,15 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm } { - JSC::Identifier identifier = JSC::Identifier::fromString(vm, "readableStreamToArray"_s); object->putDirectBuiltinFunction(vm, this, builtinNames.readableStreamToArrayPublicName(), readableStreamReadableStreamToArrayCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::DontDelete | PropertyAttribute::ReadOnly); } + { + JSC::Identifier identifier = JSC::Identifier::fromString(vm, "hashCode"_s); + object->putDirectNativeFunction(vm, this, identifier, 1, functionHashCode, NoIntrinsic, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0); + } + extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { JSC::Identifier::fromString(vm, jsClass->className()), JSC::JSValue(object), JSC::PropertyAttribute::DontDelete | 0 }); |