bool jsval_to_animationInfo(JSContext* cx, JS::HandleValue vp, cocostudio::timeline::AnimationInfo* ret)
{
    JS::RootedObject tmp(cx);
    JS::RootedValue jsName(cx);
    JS::RootedValue jsStartId(cx);
    JS::RootedValue jsEndId(cx);
    std::string name;
    double startIndex, endIndex;
    
    bool ok = vp.isObject() &&
    JS_ValueToObject(cx, vp, &tmp) &&
    JS_GetProperty(cx, tmp, "name", &jsName) &&
    JS_GetProperty(cx, tmp, "startIndex", &jsStartId) &&
    JS_GetProperty(cx, tmp, "endIndex", &jsEndId) &&
    JS::ToNumber(cx, jsStartId, &startIndex) &&
    JS::ToNumber(cx, jsEndId, &endIndex) &&
    jsval_to_std_string(cx, jsName, &name) &&
    !std::isnan(startIndex) && !std::isnan(endIndex);
    
    JSB_PRECONDITION3(ok, cx, false, "Error processing arguments");
    
    ret->name = name;
    ret->startIndex = (int)startIndex;
    ret->endIndex = (int)endIndex;
    return true;
}
void installGlobalFunction(
    JSGlobalContextRef ctx,
    const char* name,
    JSObjectCallAsFunctionCallback callback) {
  String jsName(ctx, name);
  JSObjectRef functionObj = JSC_JSObjectMakeFunctionWithCallback(
    ctx, jsName, callback);
  Object::getGlobalObject(ctx).setProperty(jsName, Value(ctx, functionObj));
}
Exemple #3
0
KJS::JSObject *Engine::addObject( QObject *obj, KJS::JSObject *parent, const KJS::UString &name ) const
{
    KJS::ExecState *exec = dptr->m_interpreter->globalExec();
    KJS::JSObject *returnObject = KJSEmbed::createQObject(exec , obj, KJSEmbed::ObjectBinding::CPPOwned );
    KJS::Identifier jsName( !name.isEmpty() ? name : toUString(obj->objectName()) );

    parent->putDirect(jsName, returnObject, KJS::DontDelete|KJS::ReadOnly );
    return returnObject;
}