diff options
Diffstat (limited to 'src/javascript/jsc/bindings/bindings.cpp')
-rw-r--r-- | src/javascript/jsc/bindings/bindings.cpp | 346 |
1 files changed, 342 insertions, 4 deletions
diff --git a/src/javascript/jsc/bindings/bindings.cpp b/src/javascript/jsc/bindings/bindings.cpp index 1cf55cff8..7120285c1 100644 --- a/src/javascript/jsc/bindings/bindings.cpp +++ b/src/javascript/jsc/bindings/bindings.cpp @@ -16,6 +16,54 @@ #include <JavaScriptCore/VM.h> #include <JavaScriptCore/WasmFaultSignalHandler.h> #include <wtf/text/StringCommon.h> +#include <JavaScriptCore/FunctionConstructor.h> +#include <JavaScriptCore/JSNativeStdFunction.h> +#include <JavaScriptCore/Completion.h> +#include <JavaScriptCore/JSModuleRecord.h> +#include <JavaScriptCore/ParserError.h> +#include <JavaScriptCore/JSString.h> +#include <JavaScriptCore/JSMap.h> +#include <JavaScriptCore/JSSet.h> + +template<class CppType, typename ZigType> +class Wrap { +public: + Wrap(){ + }; + + Wrap(ZigType zig){ + result = zig; + cpp = static_cast<CppType*>(static_cast<void*>(&zig)); + }; + + Wrap(CppType _cpp){ + char* buffer = alignedBuffer(); + memcpy(buffer, std::move(reinterpret_cast<char*>(reinterpret_cast<void*>(&_cpp))), sizeof(CppType)); + cpp = reinterpret_cast<CppType*>(buffer); + }; + + + ~Wrap(){}; + + char* alignedBuffer() { + return result.bytes + alignof(CppType) - reinterpret_cast<intptr_t>(result.bytes) % alignof(CppType); + } + + ZigType result; + CppType* cpp; + + static ZigType wrap(CppType obj) { + return *static_cast<ZigType*>(static_cast<void*>(&obj)); + } + + static ZigType wrap(CppType* obj) { + return *static_cast<ZigType*>(static_cast<void*>(obj)); + } +}; + + + + template<class To, class From> To cast(From v) @@ -29,8 +77,297 @@ To ccast(From v) return *static_cast<const To*>(static_cast<const void*>(v)); } +typedef JSC__JSValue (* NativeCallbackFunction)(void* arg0, JSC__JSGlobalObject* arg1, JSC__CallFrame* arg2); + +static const JSC::ArgList makeArgs(JSC__JSValue* v, size_t count) { + JSC::MarkedArgumentBuffer args = JSC::MarkedArgumentBuffer(); + args.ensureCapacity(count); + for (size_t i = 0; i < count; ++i) { + args.append(JSC::JSValue::decode(v[i])); + } + + return JSC::ArgList(args); +} + + extern "C" { +// #pragma mark - JSC::PropertyNameArray + +// CPP_DECL size_t JSC__PropertyNameArray__length(JSC__PropertyNameArray* arg0); +// CPP_DECL const JSC__PropertyName* JSC__PropertyNameArray__next(JSC__PropertyNameArray* arg0, size_t arg1); +// CPP_DECL void JSC__PropertyNameArray__release(JSC__PropertyNameArray* arg0); + +#pragma mark - JSC::JSCell + +JSC__JSObject* JSC__JSCell__getObject(JSC__JSCell* arg0) { + return arg0->getObject(); +} +bWTF__String JSC__JSCell__getString(JSC__JSCell* arg0, JSC__JSGlobalObject* arg1) { + return Wrap<WTF__String, bWTF__String>::wrap(arg0->getString(arg1)); +} +char JSC__JSCell__getType(JSC__JSCell* arg0) { + return arg0->type(); +} + +#pragma mark - JSC::JSString + +JSC__JSString* JSC__JSString__createFromOwnedString(JSC__VM* arg0, const WTF__String* arg1) { + return JSC::jsOwnedString(reinterpret_cast<JSC__VM&>(arg0), reinterpret_cast<const WTF__String&>(arg1)); +} +JSC__JSString* JSC__JSString__createFromString(JSC__VM* arg0, const WTF__String* arg1) { + return JSC::jsString(reinterpret_cast<JSC__VM&>(arg0), reinterpret_cast<const WTF__String&>(arg1)); +} +bool JSC__JSString__eql(const JSC__JSString* arg0, JSC__JSGlobalObject* obj, JSC__JSString* arg2) { + return arg0->equal(obj, arg2); +} +bool JSC__JSString__is8Bit(const JSC__JSString* arg0) { + return arg0->is8Bit(); +}; +size_t JSC__JSString__length(const JSC__JSString* arg0) { + return arg0->length(); +} +JSC__JSObject* JSC__JSString__toObject(JSC__JSString* arg0, JSC__JSGlobalObject* arg1) { + return arg0->toObject(arg1); +} +bWTF__String JSC__JSString__value(JSC__JSString* arg0, JSC__JSGlobalObject* arg1) { + auto wrap = Wrap<WTF__String, bWTF__String>::wrap(arg0->value(arg1)); + return wrap.result; +} + +#pragma mark - JSC::JSModuleLoader + +// JSC__JSValue JSC__JSModuleLoader__dependencyKeysIfEvaluated(JSC__JSModuleLoader* arg0, JSC__JSGlobalObject* arg1, JSC__JSModuleRecord* arg2); + +bool JSC__JSModuleLoader__checkSyntax(JSC__JSGlobalObject* arg0, const JSC__SourceCode* arg1, bool arg2) { + JSC::ParserError error; + bool result = false; + if (arg2) { + result = JSC::checkModuleSyntax(arg0, reinterpret_cast<const JSC::SourceCode&>(arg1), error); + } else { + result = JSC::checkSyntax(reinterpret_cast<JSC__VM&>(arg0->vm()), reinterpret_cast<const JSC::SourceCode&>(arg1), error); + } + + return result; + +} +JSC__JSValue JSC__JSModuleLoader__evaluate(JSC__JSGlobalObject* arg0, const JSC__SourceCode* arg1, JSC__JSValue JSValue2, JSC__Exception** arg3) { + WTF::NakedPtr<JSC::Exception> returnedException; + + auto val = JSC::JSValue::encode(JSC::evaluate(arg0, reinterpret_cast<const JSC__SourceCode&>(arg1), JSC::JSValue::decode(JSValue2), returnedException)); + *arg3 = returnedException.get(); + return val; +} +JSC__JSInternalPromise* JSC__JSModuleLoader__importModule(JSC__JSGlobalObject* arg0, const JSC__Identifier* arg1) { + return JSC::importModule(arg0, reinterpret_cast<JSC::Identifier&>(arg1), JSC::JSValue{}, JSC::JSValue{}); +} +JSC__JSValue JSC__JSModuleLoader__linkAndEvaluateModule(JSC__JSGlobalObject* arg0, const JSC__Identifier* arg1) { + return JSC::JSValue::encode(JSC::linkAndEvaluateModule(arg0, reinterpret_cast<const JSC::Identifier&>(arg1), JSC::JSValue{})); +} +JSC__JSInternalPromise* JSC__JSModuleLoader__loadAndEvaluateModule(JSC__JSGlobalObject* arg0, const WTF__String* arg1) { + return JSC::loadAndEvaluateModule(arg0, reinterpret_cast<const WTF__String&>(arg1), JSC::JSValue{}, JSC::JSValue{}); +} +JSC__JSInternalPromise* JSC__JSModuleLoader__loadAndEvaluateModuleEntryPoint(JSC__JSGlobalObject* arg0, const JSC__SourceCode* arg1) { + return JSC::loadAndEvaluateModule(arg0, reinterpret_cast<const JSC__SourceCode&>(arg1), JSC::JSValue{}); +} + +#pragma mark - JSC::JSModuleRecord + +bJSC__SourceCode JSC__JSModuleRecord__sourceCode(JSC__JSModuleRecord* arg0) { + Wrap<JSC::SourceCode, bJSC__SourceCode> wrapped = Wrap<JSC::SourceCode, bJSC__SourceCode>(arg0->sourceCode()); + return wrapped.result; +} + + +#pragma mark - JSC::JSPromise + +void JSC__JSPromise__reject(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2) { + arg0->reject(arg1, JSC::JSValue::decode(JSValue2)); +} +void JSC__JSPromise__rejectAsHandled(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2) { + arg0->rejectAsHandled(arg1, JSC::JSValue::decode(JSValue2)); +} +void JSC__JSPromise__rejectAsHandledException(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__Exception* arg2) { + arg0->rejectAsHandled(arg1,arg2); +} +JSC__JSPromise* JSC__JSPromise__rejectedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1) { + return JSC::JSPromise::rejectedPromise(arg0, JSC::JSValue::decode(JSValue1)); +} +// void JSC__JSPromise__rejectException(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__Exception* arg2) { +// JSC::JSPromise::rejec +// } +void JSC__JSPromise__rejectWithCaughtException(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, bJSC__ThrowScope arg2) { + Wrap<JSC::ThrowScope, bJSC__ThrowScope> wrapped = Wrap<JSC::ThrowScope, bJSC__ThrowScope>(arg2); + + arg0->rejectWithCaughtException(arg1, *wrapped.cpp); +} +void JSC__JSPromise__resolve(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2) { + arg0->resolve(arg1, JSC::JSValue::decode(JSValue2)); +} +JSC__JSPromise* JSC__JSPromise__resolvedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1) { + return JSC::JSPromise::resolvedPromise(arg0, JSC::JSValue::decode(JSValue1)); +} + +JSC__JSValue JSC__JSPromise__result(const JSC__JSPromise* arg0, JSC__VM* arg1) { + return JSC::JSValue::encode(arg0->result(reinterpret_cast<JSC::VM&>(arg1))); +} +uint32_t JSC__JSPromise__status(const JSC__JSPromise* arg0, JSC__VM* arg1) { + switch (arg0->status(reinterpret_cast<JSC::VM&>(arg1))) { + case JSC::JSPromise::Status::Pending: return 0; + case JSC::JSPromise::Status::Fulfilled: return 1; + case JSC::JSPromise::Status::Rejected: return 2; + default: return 255; + } +} +bool JSC__JSPromise__isHandled(const JSC__JSPromise* arg0, JSC__VM* arg1) { + return arg0->isHandled(reinterpret_cast<JSC::VM&>(arg1)); +} + + +// bool JSC__JSPromise__isInternal(JSC__JSPromise* arg0, JSC__VM* arg1) { +// return arg0->inf +// } + + +#pragma mark - JSC::SourceOrigin + +bJSC__SourceOrigin JSC__SourceOrigin__fromURL(const WTF__URL* arg0) { + + auto wrap = Wrap<JSC::SourceOrigin, bJSC__SourceOrigin>(JSC::SourceOrigin(reinterpret_cast<const WTF::URL&>(arg0))); + return wrap.result; +} + +#pragma mark - JSC::SourceCode + +bJSC__SourceCode JSC__SourceCode__fromString(const WTF__String* arg0, const JSC__SourceOrigin* arg1, WTF__String* arg2, char SourceType3) { + auto wrap = Wrap<JSC::SourceCode, bJSC__SourceCode>( + JSC::makeSource( + reinterpret_cast<const WTF::String&>(arg0), + reinterpret_cast<const JSC::SourceOrigin&>(arg1), + arg2 == nullptr ? WTF::String() : *arg2, + WTF::TextPosition(), + SourceType3 == 0 ? JSC::SourceProviderSourceType::Program : JSC::SourceProviderSourceType::Module + )); + + return wrap.result; +} + + +#pragma mark - JSC::JSFunction + +JSC__JSValue JSC__JSFunction__callWithArguments(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue* arg2, size_t arg3, JSC__Exception** arg4, char* arg5) { + auto args = makeArgs(arg2, arg3); + return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), JSC::JSValue::decode(JSValue0), args, arg5)); +} +JSC__JSValue JSC__JSFunction__callWithArgumentsAndThis(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject* arg2, JSC__JSValue* arg3, size_t arg4, JSC__Exception** arg5, char* arg6) { + auto args = makeArgs(arg3, arg4); + return JSC::JSValue::encode(JSC::call(arg2, JSC::JSValue::decode(JSValue0), JSC::JSValue::decode(JSValue1), args, arg6)); +} +JSC__JSValue JSC__JSFunction__callWithoutAnyArgumentsOrThis(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__Exception** arg2, char* arg3) { + return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), JSC::JSValue::decode(JSValue0), JSC::ArgList(), arg3)); +} +JSC__JSValue JSC__JSFunction__callWithThis(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, JSC__Exception** arg3, char* arg4) { + return JSC::JSValue::encode(JSC::call(arg1, JSC::JSValue::decode(JSValue0), JSC::JSValue::decode(JSValue2), JSC::ArgList(), arg4)); +} +JSC__JSValue JSC__JSFunction__constructWithArguments(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue* arg2, size_t arg3, JSC__Exception** arg4, char* arg5) { + auto args = makeArgs(arg2, arg3); + return JSC::JSValue::encode(JSC::construct(arg1, JSC::JSValue::decode(JSValue0), args, arg5)); +} + +JSC__JSValue JSC__JSFunction__constructWithArgumentsAndNewTarget(JSC__JSValue JSValue0, JSC__JSValue JSValue1, JSC__JSGlobalObject* arg2, JSC__JSValue* arg3, size_t arg4, JSC__Exception** arg5, char* arg6) { + auto args = makeArgs(arg3, arg4); + return JSC::JSValue::encode(JSC::construct(arg2, JSC::JSValue::decode(JSValue0), JSC::JSValue::decode(JSValue0), args, arg6)); +} +JSC__JSValue JSC__JSFunction__constructWithNewTarget(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2, JSC__Exception** arg3, char* arg4) { + return JSC::JSValue::encode(JSC::construct(arg1, JSC::JSValue::decode(JSValue0), JSC::JSValue::decode(JSValue2), JSC::ArgList(), arg4)); +} +JSC__JSValue JSC__JSFunction__constructWithoutAnyArgumentsOrNewTarget(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1, JSC__Exception** arg2, char* arg3) { + return JSC::JSValue::encode(JSC::construct(arg1, JSC::JSValue::decode(JSValue0), JSC::ArgList(), arg3)); +} + +JSC__JSFunction* JSC__JSFunction__createFromNative(JSC__JSGlobalObject* arg0, uint16_t arg1, const WTF__String* arg2, void* ctx, NativeCallbackFunction callback) { + return JSC::JSNativeStdFunction::create( + reinterpret_cast<JSC::VM&>(arg0->vm()), + arg0, + arg1, + arg2 != nullptr ? *arg2 : WTF::String(), + [ctx, callback](JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame) -> JSC::EncodedJSValue { + return callback(ctx, globalObject, callFrame); + + }); +} +// JSC__JSFunction* JSC__JSFunction__createFromSourceCode( +// JSC__JSGlobalObject* arg0, +// const char* arg1, +// uint16_t arg2, +// JSC__JSValue arg3, +// uint16_t arg4, +// const JSC__SourceCode* source, +// JSC__SourceOrigin* origin, +// JSC__JSObject** exception +// ) { +// JSC::VM& vm = reinterpret_cast<JSC::VM&>(arg0->vm()); +// JSC::Identifier functionName = JSC::Identifier::fromString(vm, arg2 && arg1 != nullptr ? WTF::StringImpl(static_cast<const LChar*>(arg1), arg2) : vm->propertyNames->anonymous.impl()); + +// JSC::FunctionExecutable* function = JSC::FunctionExecutable::fromGlobalCode( +// functionName, +// arg0, +// source, +// exception, +// 0, +// nullptr, +// ); + + + +// } + +bWTF__String JSC__JSFunction__displayName(JSC__JSFunction* arg0, JSC__VM* arg1) { + auto wrap = Wrap<WTF::String, bWTF__String>(arg0->displayName(reinterpret_cast<JSC::VM&>(arg1))); + return wrap.result; +}; +bWTF__String JSC__JSFunction__getName(JSC__JSFunction* arg0, JSC__VM* arg1) { + auto wrap = Wrap<WTF::String, bWTF__String>(arg0->name(reinterpret_cast<JSC::VM&>(arg1))); + return wrap.result; +}; +bWTF__String JSC__JSFunction__calculatedDisplayName(JSC__JSFunction* arg0, JSC__VM* arg1) { + auto wrap = Wrap<WTF::String, bWTF__String>(arg0->calculatedDisplayName(reinterpret_cast<JSC::VM&>(arg1))); + return wrap.result; +}; +#pragma mark - JSC::JSGlobalObject + +JSC__ArrayIteratorPrototype* JSC__JSGlobalObject__arrayIteratorPrototype(JSC__JSGlobalObject* arg0) { return arg0->arrayIteratorPrototype(); }; +JSC__ArrayPrototype* JSC__JSGlobalObject__arrayPrototype(JSC__JSGlobalObject* arg0) { return arg0->arrayPrototype(); }; +JSC__AsyncFunctionPrototype* JSC__JSGlobalObject__asyncFunctionPrototype(JSC__JSGlobalObject* arg0) { return arg0->asyncFunctionPrototype(); }; +JSC__AsyncGeneratorFunctionPrototype* JSC__JSGlobalObject__asyncGeneratorFunctionPrototype(JSC__JSGlobalObject* arg0) { return arg0->asyncGeneratorFunctionPrototype(); }; +JSC__AsyncGeneratorPrototype* JSC__JSGlobalObject__asyncGeneratorPrototype(JSC__JSGlobalObject* arg0) { return arg0->asyncGeneratorPrototype(); }; +JSC__AsyncIteratorPrototype* JSC__JSGlobalObject__asyncIteratorPrototype(JSC__JSGlobalObject* arg0) { return arg0->asyncIteratorPrototype(); }; +JSC__BigIntPrototype* JSC__JSGlobalObject__bigIntPrototype(JSC__JSGlobalObject* arg0) { return arg0->bigIntPrototype(); }; +JSC__JSObject* JSC__JSGlobalObject__booleanPrototype(JSC__JSGlobalObject* arg0) { return arg0->booleanPrototype(); }; +JSC__JSObject* JSC__JSGlobalObject__datePrototype(JSC__JSGlobalObject* arg0) { return arg0->datePrototype(); }; +JSC__JSObject* JSC__JSGlobalObject__errorPrototype(JSC__JSGlobalObject* arg0) { return arg0->errorPrototype(); }; +JSC__FunctionPrototype* JSC__JSGlobalObject__functionPrototype(JSC__JSGlobalObject* arg0) { return arg0->functionPrototype(); }; +JSC__GeneratorFunctionPrototype* JSC__JSGlobalObject__generatorFunctionPrototype(JSC__JSGlobalObject* arg0) { return arg0->generatorFunctionPrototype(); }; +JSC__GeneratorPrototype* JSC__JSGlobalObject__generatorPrototype(JSC__JSGlobalObject* arg0) { return arg0->generatorPrototype(); }; +JSC__IteratorPrototype* JSC__JSGlobalObject__iteratorPrototype(JSC__JSGlobalObject* arg0) { return arg0->iteratorPrototype(); }; +JSC__JSObject* JSC__JSGlobalObject__jsSetPrototype(JSC__JSGlobalObject* arg0) { return arg0->jsSetPrototype(); }; +JSC__MapIteratorPrototype* JSC__JSGlobalObject__mapIteratorPrototype(JSC__JSGlobalObject* arg0) { return arg0->mapIteratorPrototype(); }; +JSC__JSObject* JSC__JSGlobalObject__mapPrototype(JSC__JSGlobalObject* arg0) { return arg0->mapPrototype(); }; +JSC__JSObject* JSC__JSGlobalObject__numberPrototype(JSC__JSGlobalObject* arg0) { return arg0->numberPrototype(); }; +JSC__ObjectPrototype* JSC__JSGlobalObject__objectPrototype(JSC__JSGlobalObject* arg0) { return arg0->objectPrototype(); }; +JSC__JSPromisePrototype* JSC__JSGlobalObject__promisePrototype(JSC__JSGlobalObject* arg0) { return arg0->promisePrototype(); }; +JSC__RegExpPrototype* JSC__JSGlobalObject__regExpPrototype(JSC__JSGlobalObject* arg0) { return arg0->regExpPrototype(); }; +JSC__SetIteratorPrototype* JSC__JSGlobalObject__setIteratorPrototype(JSC__JSGlobalObject* arg0) { return arg0->setIteratorPrototype(); }; +JSC__StringPrototype* JSC__JSGlobalObject__stringPrototype(JSC__JSGlobalObject* arg0) { return arg0->stringPrototype(); }; +JSC__JSObject* JSC__JSGlobalObject__symbolPrototype(JSC__JSGlobalObject* arg0) { return arg0->symbolPrototype(); }; + +JSC__VM* JSC__JSGlobalObject__vm(JSC__JSGlobalObject* arg0) { + return &arg0->vm(); +}; +// JSC__JSObject* JSC__JSGlobalObject__createError(JSC__JSGlobalObject* arg0, char ErrorType1, WTF__String* arg2) {}; +// JSC__JSObject* JSC__JSGlobalObject__throwError(JSC__JSGlobalObject* arg0, JSC__JSObject* arg1) {}; + + #pragma mark - JSC::JSValue JSC__JSCell* JSC__JSValue__asCell(JSC__JSValue JSValue0) { @@ -184,8 +521,9 @@ void JSC__ThrowScope__clearException(JSC__ThrowScope* arg0) { arg0->clearException(); }; bJSC__ThrowScope JSC__ThrowScope__declare(JSC__VM* arg0, char* arg1, char* arg2, size_t arg3) { - JSC::ThrowScope scope = JSC::ThrowScope(reinterpret_cast<JSC::VM&>(arg0)); - return cast<bJSC__ThrowScope>(&scope); + Wrap<JSC::ThrowScope, bJSC__ThrowScope> wrapped = Wrap<JSC::ThrowScope, bJSC__ThrowScope>(); + wrapped.cpp = new (wrapped.alignedBuffer()) JSC::ThrowScope(reinterpret_cast<JSC::VM&>(arg0)); + return wrapped.result; }; JSC__Exception* JSC__ThrowScope__exception(JSC__ThrowScope* arg0) { return arg0->exception(); @@ -449,8 +787,8 @@ bWTF__String WTF__URL__password(WTF__URL* arg0) { return cast<bWTF__String>(&result); }; bWTF__StringView WTF__URL__path(WTF__URL* arg0) { - auto result = arg0->path(); - return cast<bWTF__StringView>(&result); + auto wrap = Wrap<WTF::StringView, bWTF__StringView>(arg0->path()); + return wrap.result; }; bWTF__StringView WTF__URL__protocol(WTF__URL* arg0) { auto result = arg0->protocol(); |