diff options
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 }); |