static bool js_object_external_function_callback( const jerry_api_object_t *function_object_ptr, const jerry_api_value_t *this_object_ptr, jerry_api_value_t *result_value_ptr, const jerry_api_value_t js_api_arguments[], const jerry_api_length_t argumentCount) { const auto position = JSObject::js_object_external_functions_map__.find(function_object_ptr); assert(position != JSObject::js_object_external_functions_map__.end()); auto callback = position->second; // TODO: Use current context JSContextGroup js_context_group; const auto js_context = js_context_group.CreateContext(); auto function_object = JSObject(js_context, function_object_ptr); auto this_object = JSObject(js_context, *this_object_ptr); const auto arguments = detail::to_vector(js_context, js_api_arguments, argumentCount); auto callback_result = callback(function_object, this_object, arguments); auto callback_result_value = static_cast<jerry_api_value_t>(callback_result); // callback value should be considered "unmanaged" from Daisy callback_result.unmanaged(); detail::js_jerry_api_value_make_copy(callback_result_value, result_value_ptr); return true; }
void CXFA_Occur::SetMin(int32_t iMin) { iMin = (iMin < 0) ? 1 : iMin; JSObject()->SetInteger(XFA_Attribute::Min, iMin, false); int32_t iMax = GetMax(); if (iMax > 0 && iMax < iMin) { iMax = iMin; JSObject()->SetInteger(XFA_Attribute::Max, iMax, false); } }
void CXFA_Occur::SetMax(int32_t iMax) { iMax = (iMax != -1 && iMax < 1) ? 1 : iMax; JSObject()->SetInteger(XFA_Attribute::Max, iMax, false); int32_t iMin = GetMin(); if (iMax != -1 && iMax < iMin) { iMin = iMax; JSObject()->SetInteger(XFA_Attribute::Min, iMin, false); } }
JSObject JSObject::CallAsConstructor(const std::vector<JSValue>& arguments) { HAL_JSOBJECT_LOCK_GUARD; if (!IsConstructor()) { detail::ThrowRuntimeError("JSObject", "This JavaScript object is not a constructor."); } JSValueRef exception { nullptr }; JSObjectRef js_object_ref = nullptr; if (!arguments.empty()) { const auto arguments_array = detail::to_vector(arguments); js_object_ref = JSObjectCallAsConstructor(static_cast<JSContextRef>(js_context__), js_object_ref__, arguments_array.size(), &arguments_array[0], &exception); } else { js_object_ref = JSObjectCallAsConstructor(static_cast<JSContextRef>(js_context__), js_object_ref__, 0, nullptr, &exception); } if (exception) { // If this assert fails then we need to JSValueUnprotect // js_object_ref. assert(!js_object_ref); detail::ThrowRuntimeError("JSObject", JSValue(js_context__, exception)); } // postcondition assert(js_object_ref); return JSObject(js_context__, js_object_ref); }
std::tuple<int32_t, int32_t, int32_t> CXFA_Occur::GetOccurInfo() { int32_t iMin = GetMin(); int32_t iMax = GetMax(); Optional<int32_t> init = JSObject()->TryInteger(XFA_Attribute::Initial, false); return {iMin, iMax, init && *init >= iMin ? *init : iMin}; }
JSObject JSClass::JSObjectMakeFunctionWithCallback(const JSContext& js_context, const std::string& name, JSObjectCallAsFunctionCallback callback) const { auto js_api_object = jerry_api_create_external_function(js_object_external_function_callback); auto function_object = JSObject(js_context, js_api_object); const auto position = JSObject::js_object_external_functions_map__.find(js_api_object); assert(position == JSObject::js_object_external_functions_map__.end()); JSObject::js_object_external_functions_map__.emplace(js_api_object, callback); return function_object; }
JSValue::operator JSObject() const { HAL_JSVALUE_LOCK_GUARD; JSValueRef exception { nullptr }; JSObjectRef js_object_ref = JSValueToObject(static_cast<JSContextRef>(js_context__), js_value_ref__, &exception); if (exception) { // If this assert fails then we need to JSValueUnprotect // js_object_ref. assert(!js_object_ref); detail::ThrowRuntimeError("JSValue", JSValue(js_context__, exception)); } assert(js_object_ref); return JSObject(js_context__, js_object_ref); }
JSObject JSObject::FindJSObject(JSContextRef js_context_ref, JSObjectRef js_object_ref) { HAL_JSOBJECT_LOCK_GUARD_STATIC; const auto key = reinterpret_cast<std::intptr_t>(js_object_ref); const auto position = js_object_ref_to_js_context_ref_map__.find(key); const bool found = position != js_object_ref_to_js_context_ref_map__.end(); // precondition if (found) { js_context_ref = reinterpret_cast<JSContextRef>(std::get<0>(position -> second)); } HAL_LOG_TRACE("JSObject::FindJSObject: found = ", found, " for JSObjectRef ", js_object_ref, ", JSContextRef = ", js_context_ref); return JSObject(JSContext(js_context_ref), js_object_ref); }
int32_t CXFA_Occur::GetMin() { Optional<int32_t> min = JSObject()->TryInteger(XFA_Attribute::Min, true); return min && *min >= 0 ? *min : 1; }
int32_t CXFA_Occur::GetMax() { Optional<int32_t> max = JSObject()->TryInteger(XFA_Attribute::Max, true); return max ? *max : GetMin(); }
JSObject JSValue::ToObject() const { assert(IsObject()); return JSObject(ctx_, instance()); }