示例#1
0
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));
}
示例#2
0
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));
}
示例#3
0
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);
}
示例#4
0
      }
      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
};