bool js_util_DirectoryUtils_walkFiles(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); js_proxy_t *proxy = jsb_get_js_proxy(obj); auto cobj = (Utils::DirectoryUtils *)(proxy ? proxy->ptr : NULL); JSB_PRECONDITION2( cobj, cx, false, "js_util_DirectoryUtils_walkFiles : Invalid Native Object"); if (argc == 4) { std::string arg0; bool arg1; std::string arg2; Utils::DirectoryUtils::walkCallback arg3; bool ok = true; do { ok = jsval_to_std_string(cx, args.get(0), &arg0); if (!ok) break; ok = jsval_to_bool(cx, args.get(1), &arg1); if (!ok) break; ok = jsval_to_std_string(cx, args.get(2), &arg2); if (!ok) break; ok = JS_TypeOfValue(cx, args.get(3)) == JSTYPE_FUNCTION; if (!ok) break; JSObject* thisObj = JS_THIS_OBJECT(cx, vp); // TODO 其它用法 std::shared_ptr<JSFunctionWrapper> func(new JSFunctionWrapper(cx, thisObj, args.get(3))); arg3 = [=](const char* arg0, const char* arg1, const char* arg2) -> void { JS::RootedValue rval(cx); JS::AutoValueVector args(cx); args.reserve(3); args.append(STRING_TO_JSVAL(c_str_to_js_str(cx, arg0))); args.append(STRING_TO_JSVAL(c_str_to_js_str(cx, arg1))); args.append(STRING_TO_JSVAL(c_str_to_js_str(cx, arg2))); bool ok = func->invoke(args, &rval); if (!ok && JS_IsExceptionPending(cx)) { JS_ReportPendingException(cx); } }; cobj->walkFiles(arg0.c_str(), arg1, arg2.c_str(), arg3); } while (0); JSB_PRECONDITION2(ok, cx, false, "js_util_DirectoryUtils_walkFiles : Error processing arguments"); args.rval().setUndefined(); return true; } JS_ReportError(cx, "js_util_DirectoryUtils_walkFiles : wrong number of arguments"); return false; }