JSValue JSC_HOST_CALL mathProtoFuncACos(ExecState* exec, JSObject*, JSValue, const ArgList& args) { return jsDoubleNumber(exec, acos(args.at(0).toNumber(exec))); }
// ECMA 15.6.1 static JSValue QT_FASTCALL callBooleanConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) { return jsBoolean(args.at(0).toBoolean(exec)); }
JSValue JSC_HOST_CALL mathProtoFuncFloor(ExecState* exec, JSObject*, JSValue, const ArgList& args) { return jsNumber(exec, floor(args.at(0).toNumber(exec))); }
// ECMA 15.5.1 static JSValue JSC_HOST_CALL callStringConstructor(ExecState* exec, JSObject*, JSValue, const ArgList& args) { if (args.isEmpty()) return jsEmptyString(exec); return jsString(exec, args.at(0).toString(exec)); }
JSValue JSSQLTransaction::executeSql(ExecState* exec, const ArgList& args) { if (args.isEmpty()) { setDOMException(exec, SYNTAX_ERR); return jsUndefined(); } String sqlStatement = args.at(0).toString(exec); if (exec->hadException()) return jsUndefined(); // Now assemble the list of SQL arguments Vector<SQLValue> sqlValues; if (!args.at(1).isUndefinedOrNull()) { JSObject* object = args.at(1).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } JSValue lengthValue = object->get(exec, exec->propertyNames().length); if (exec->hadException()) return jsUndefined(); unsigned length = lengthValue.toUInt32(exec); if (exec->hadException()) return jsUndefined(); for (unsigned i = 0 ; i < length; ++i) { JSValue value = object->get(exec, i); if (exec->hadException()) return jsUndefined(); if (value.isNull()) sqlValues.append(SQLValue()); else if (value.isNumber()) sqlValues.append(value.uncheckedGetNumber()); else { // Convert the argument to a string and append it sqlValues.append(value.toString(exec)); if (exec->hadException()) return jsUndefined(); } } } RefPtr<SQLStatementCallback> callback; if (!args.at(2).isUndefinedOrNull()) { JSObject* object = args.at(2).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } callback = JSCustomSQLStatementCallback::create(object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())); } RefPtr<SQLStatementErrorCallback> errorCallback; if (!args.at(3).isUndefinedOrNull()) { JSObject* object = args.at(3).getObject(); if (!object) { setDOMException(exec, TYPE_MISMATCH_ERR); return jsUndefined(); } errorCallback = JSCustomSQLStatementErrorCallback::create(object, static_cast<JSDOMGlobalObject*>(exec->dynamicGlobalObject())); } ExceptionCode ec = 0; m_impl->executeSQL(sqlStatement, sqlValues, callback.release(), errorCallback.release(), ec); setDOMException(exec, ec); return jsUndefined(); }
JSValuePtr JavaInstance::invokeMethod (ExecState *exec, const MethodList &methodList, const ArgList &args) { int i, count = args.size(); jvalue *jArgs; JSValuePtr resultValue; Method *method = 0; size_t numMethods = methodList.size(); // Try to find a good match for the overloaded method. The // fundamental problem is that JavaScript doesn have the // notion of method overloading and Java does. We could // get a bit more sophisticated and attempt to does some // type checking as we as checking the number of parameters. Method *aMethod; for (size_t methodIndex = 0; methodIndex < numMethods; methodIndex++) { aMethod = methodList[methodIndex]; if (aMethod->numParameters() == count) { method = aMethod; break; } } if (method == 0) { JS_LOG ("unable to find an appropiate method\n"); return jsUndefined(); } const JavaMethod *jMethod = static_cast<const JavaMethod*>(method); JS_LOG ("call %s %s on %p\n", UString(jMethod->name()).UTF8String().c_str(), jMethod->signature(), _instance->_instance); if (count > 0) { jArgs = (jvalue *)malloc (count * sizeof(jvalue)); } else jArgs = 0; for (i = 0; i < count; i++) { JavaParameter* aParameter = jMethod->parameterAt(i); jArgs[i] = convertValueToJValue(exec, args.at(exec, i), aParameter->getJNIType(), aParameter->type()); JS_LOG("arg[%d] = %s\n", i, args.at(exec, i).toString(exec).ascii()); } jvalue result; // Try to use the JNI abstraction first, otherwise fall back to // nornmal JNI. The JNI dispatch abstraction allows the Java plugin // to dispatch the call on the appropriate internal VM thread. RootObject* rootObject = this->rootObject(); if (!rootObject) return jsUndefined(); bool handled = false; if (rootObject->nativeHandle()) { jobject obj = _instance->_instance; JSValuePtr exceptionDescription = noValue(); const char *callingURL = 0; // FIXME, need to propagate calling URL to Java handled = dispatchJNICall(exec, rootObject->nativeHandle(), obj, jMethod->isStatic(), jMethod->JNIReturnType(), jMethod->methodID(obj), jArgs, result, callingURL, exceptionDescription); if (exceptionDescription) { throwError(exec, GeneralError, exceptionDescription.toString(exec)); free (jArgs); return jsUndefined(); } } // The following code can be conditionally removed once we have a Tiger update that // contains the new Java plugin. It is needed for builds prior to Tiger. if (!handled) { jobject obj = _instance->_instance; switch (jMethod->JNIReturnType()){ case void_type: callJNIMethodIDA<void>(obj, jMethod->methodID(obj), jArgs); break; case object_type: result.l = callJNIMethodIDA<jobject>(obj, jMethod->methodID(obj), jArgs); break; case boolean_type: result.z = callJNIMethodIDA<jboolean>(obj, jMethod->methodID(obj), jArgs); break; case byte_type: result.b = callJNIMethodIDA<jbyte>(obj, jMethod->methodID(obj), jArgs); break; case char_type: result.c = callJNIMethodIDA<jchar>(obj, jMethod->methodID(obj), jArgs); break; case short_type: result.s = callJNIMethodIDA<jshort>(obj, jMethod->methodID(obj), jArgs); break; case int_type: result.i = callJNIMethodIDA<jint>(obj, jMethod->methodID(obj), jArgs); break; case long_type: result.j = callJNIMethodIDA<jlong>(obj, jMethod->methodID(obj), jArgs); break; case float_type: result.f = callJNIMethodIDA<jfloat>(obj, jMethod->methodID(obj), jArgs); break; case double_type: result.d = callJNIMethodIDA<jdouble>(obj, jMethod->methodID(obj), jArgs); break; case invalid_type: default: break; } } switch (jMethod->JNIReturnType()){ case void_type: { resultValue = jsUndefined(); } break; case object_type: { if (result.l != 0) { const char *arrayType = jMethod->returnType(); if (arrayType[0] == '[') { resultValue = JavaArray::convertJObjectToArray(exec, result.l, arrayType, rootObject); } else { resultValue = JavaInstance::create(result.l, rootObject)->createRuntimeObject(exec); } } else { resultValue = jsUndefined(); } } break; case boolean_type: { resultValue = jsBoolean(result.z); } break; case byte_type: { resultValue = jsNumber(exec, result.b); } break; case char_type: { resultValue = jsNumber(exec, result.c); } break; case short_type: { resultValue = jsNumber(exec, result.s); } break; case int_type: { resultValue = jsNumber(exec, result.i); } break; case long_type: { resultValue = jsNumber(exec, result.j); } break; case float_type: { resultValue = jsNumber(exec, result.f); } break; case double_type: { resultValue = jsNumber(exec, result.d); } break; case invalid_type: default: { resultValue = jsUndefined(); } break; } free (jArgs); return resultValue; }
static JSValue JSC_HOST_CALL stringFromCharCode(ExecState* exec, JSObject*, JSValue, const ArgList& args) { if (LIKELY(args.size() == 1)) return jsSingleCharacterString(exec, args.at(0).toUInt32(exec)); return stringFromCharCodeSlowCase(exec, args); }
JSValuePtr JSHTMLCollection::namedItem(ExecState* exec, const ArgList& args) { return getNamedItems(exec, impl(), Identifier(exec, args.at(exec, 0)->toString(exec))); }
TiValue JSC_HOST_CALL functionDebug(TiExcState* exec, TiObject*, TiValue, const ArgList& args) { fprintf(stderr, "--> %s\n", args.at(0).toString(exec).UTF8String().c_str()); return jsUndefined(); }
static JSValue JSC_HOST_CALL dateUTC(ExecState* exec, JSObject*, JSValue, const ArgList& args) { int n = args.size(); if (isnan(args.at(0).toNumber(exec)) || isnan(args.at(1).toNumber(exec)) || (n >= 3 && isnan(args.at(2).toNumber(exec))) || (n >= 4 && isnan(args.at(3).toNumber(exec))) || (n >= 5 && isnan(args.at(4).toNumber(exec))) || (n >= 6 && isnan(args.at(5).toNumber(exec))) || (n >= 7 && isnan(args.at(6).toNumber(exec)))) return jsNaN(exec); GregorianDateTime t; int year = args.at(0).toInt32(exec); t.year = (year >= 0 && year <= 99) ? year : year - 1900; t.month = args.at(1).toInt32(exec); t.monthDay = (n >= 3) ? args.at(2).toInt32(exec) : 1; t.hour = args.at(3).toInt32(exec); t.minute = args.at(4).toInt32(exec); t.second = args.at(5).toInt32(exec); double ms = (n >= 7) ? args.at(6).toNumber(exec) : 0; return jsNumber(exec, timeClip(gregorianDateTimeToMS(exec, t, ms, true))); }
static JSValue JSC_HOST_CALL dateParse(ExecState* exec, JSObject*, JSValue, const ArgList& args) { return jsNumber(exec, parseDate(exec, args.at(0).toString(exec))); }
AJValue JSC_HOST_CALL objectProtoFuncPropertyIsEnumerable(ExecState* exec, AJObject*, AJValue thisValue, const ArgList& args) { return jsBoolean(thisValue.toThisObject(exec)->propertyIsEnumerable(exec, Identifier(exec, args.at(0).toString(exec)))); }
AJValue JSC_HOST_CALL objectProtoFuncLookupSetter(ExecState* exec, AJObject*, AJValue thisValue, const ArgList& args) { return thisValue.toThisObject(exec)->lookupSetter(exec, Identifier(exec, args.at(0).toString(exec))); }
JSValuePtr JSNodeFilter::acceptNode(ExecState* exec, const ArgList& args) { return jsNumber(exec, impl()->acceptNode(exec, toNode(args.at(exec, 0)))); }