Esempio n. 1
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);
}
Esempio n. 2
0
        JSValueRef args[] { message.value(), nullptr };
        *exception = JSObjectMakeError(ctx, 1, args, nullptr);
      }
      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
};