JSValueRef NX::Globals::Console::Get (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef * exception) { NX::Context * context = Context::FromJsContext(ctx); if (JSObjectRef console = context->getGlobal("console")) { return console; } return context->setGlobal("console", JSObjectMake(context->toJSContext(), context->defineOrGetClass(NX::Globals::Console::Class), nullptr)); }
JSValueRef NX::Globals::Net::Get (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef * exception) { NX::Context * context = Context::FromJsContext(ctx); if (auto Net = context->getGlobal("Nexus.Net")) { return Net; } return context->setGlobal("Nexus.Net", JSObjectMake(context->toJSContext(), context->nexus()->defineOrGetClass(NX::Globals::Net::Class), nullptr)); }
JSValueRef NX::Globals::Loader::Get (JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef * exception) { NX::Context * context = NX::Context::FromJsContext(ctx); if (JSObjectRef Loader = context->getGlobal("Loader")) return Loader; JSValueRef Loader = context->evaluateScript(std::string(loader_js, loader_js + loader_js_len), nullptr, "loader.js", 1, exception); JSObjectRef loaderObject = JSValueToObject(context->toJSContext(), Loader, exception); if (!*exception) return context->setGlobal("Loader", loaderObject); return JSValueMakeUndefined(ctx); }
context->nexus()->defineOrGetClass(NX::Globals::Net::Class), nullptr)); } const JSClassDefinition NX::Globals::Net::Class { 0, kJSClassAttributeNone, "Net", nullptr, NX::Globals::Net::Properties, NX::Globals::Net::Methods }; const JSStaticValue NX::Globals::Net::Properties[] { {"SocketDevice", [](JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) -> JSValueRef { NX::Context *context = Context::FromJsContext(ctx); if (auto val = context->getGlobal("Nexus.Net.SocketDevice")) return val; JSObjectRef constructor = NX::Classes::IO::Devices::Socket::getConstructor(context); context->setGlobal("Nexus.Net.Socket", constructor); return constructor; }, nullptr, kJSPropertyAttributeNone}, {"UDPSocket", [](JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) -> JSValueRef { NX::Context *context = Context::FromJsContext(ctx); if (auto val = context->getGlobal("Nexus.Net.UDPSocket")) return val; JSObjectRef constructor = NX::Classes::IO::Devices::UDPSocket::getConstructor(context); context->setGlobal("Nexus.IO.UDPSocket", constructor); return constructor; }, nullptr, kJSPropertyAttributeNone}, { "TCP", [](JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) -> JSValueRef { NX::Context * context = Context::FromJsContext(ctx); if (auto TCP = context->getGlobal("Nexus.Net.TCP")) return TCP;
} return JSValueMakeUndefined(ctx); }, 0 }, { nullptr, nullptr, 0 } }; const JSStaticValue NX::Globals::Console::Properties[] { { "inspect", [](JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) -> JSValueRef { try { NX::Context * context = Context::FromJsContext(ctx); if (JSObjectRef inspect = context->getGlobal("console.inspect")) return inspect; JSValueRef inspect = context->evaluateScript(std::string(inspect_js, inspect_js + inspect_js_len), nullptr, "console.js", 1, exception); if (exception && *exception) throw std::runtime_error(NX::Value(ctx, *exception).toString()); context->setGlobal("console.inspect", NX::Object(context->toJSContext(), inspect).value()); return inspect; } catch(const std::exception & e) { return JSWrapException(ctx, e, exception); } }, nullptr, kJSPropertyAttributeNone }, { nullptr, nullptr, nullptr, 0} }; const JSClassDefinition NX::Globals::Console::Class { 0, kJSClassAttributeNone, "Console", nullptr, NX::Globals::Console::Properties, NX::Globals::Console::Methods };