TITANIUM_FUNCTION(File, write) { const auto js_context = this_object.get_context(); if (arguments.size() < 1) { return js_context.CreateUndefined(); } const auto _0 = arguments.at(0); const auto _1 = arguments.size() < 2 ? js_context.CreateBoolean(false) : arguments.at(1); TITANIUM_ASSERT(_1.IsBoolean()); const auto append = static_cast<bool>(_1); if (_0.IsString()) { return js_context.CreateBoolean(write(static_cast<std::string>(arguments.at(0)), append)); } else if (_0.IsObject()) { const auto js_object = static_cast<JSObject>(_0); const auto blob = js_object.GetPrivate<Titanium::Blob>(); const auto file = js_object.GetPrivate<File>(); if (blob != nullptr) { return js_context.CreateBoolean(write(blob, append)); } else if (file != nullptr) { return js_context.CreateBoolean(write(file, append)); } } return js_context.CreateNull(); }
TITANIUM_FUNCTION(CoreDispatcher, ShouldYield) { auto context = get_context(); if (arguments.size() == 1) { auto _0 = arguments.at(0); TITANIUM_ASSERT_AND_THROW(_0.IsNumber(), "Expected Number"); auto priority = static_cast<::Windows::UI::Core::CoreDispatcherPriority>(static_cast<int32_t>(_0)); // TODO Look up enum in metadata to know what type it's value is? auto method_result = unwrap()->ShouldYield(priority); auto result = context.CreateBoolean(method_result); return result; } if (arguments.size() == 0) { auto method_result = unwrap()->ShouldYield(); auto result = context.CreateBoolean(method_result); return result; } // Catch-all if no arg count matches! TITANIUM_LOG_DEBUG("No method signature matched CoreDispatcher::ShouldYield with # of args: ", arguments.size()); return context.CreateUndefined(); }
void GDCCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { returnValue->lexemeValue = CreateBoolean(theEnv,GetDynamicConstraintChecking(theEnv)); }
void NextMethodPCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { returnValue->lexemeValue = CreateBoolean(theEnv,NextMethodP(theEnv)); }
/****************************************************************************** NAME : AnyFacts DESCRIPTION : Determines if there any existing facts which satisfy the query INPUTS : None RETURNS : True if the query is satisfied, false otherwise SIDE EFFECTS : The query template-expressions are evaluated once, and the query boolean-expression is evaluated zero or more times (depending on fact restrictions and how early the expression evaluates to true - if at all). NOTES : H/L Syntax : See FactParseQueryNoAction() ******************************************************************************/ void AnyFacts( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { QUERY_TEMPLATE *qtemplates; unsigned rcnt; bool testResult; qtemplates = DetermineQueryTemplates(theEnv,GetFirstArgument()->nextArg, "any-factp",&rcnt); if (qtemplates == NULL) { returnValue->lexemeValue = FalseSymbol(theEnv); return; } PushQueryCore(theEnv); FactQueryData(theEnv)->QueryCore = get_struct(theEnv,query_core); FactQueryData(theEnv)->QueryCore->solns = (Fact **) gm2(theEnv,(sizeof(Fact *) * rcnt)); FactQueryData(theEnv)->QueryCore->query = GetFirstArgument(); testResult = TestForFirstInChain(theEnv,qtemplates,0); FactQueryData(theEnv)->AbortQuery = false; rm(theEnv,FactQueryData(theEnv)->QueryCore->solns,(sizeof(Fact *) * rcnt)); rtn_struct(theEnv,query_core,FactQueryData(theEnv)->QueryCore); PopQueryCore(theEnv); DeleteQueryTemplates(theEnv,qtemplates); returnValue->lexemeValue = CreateBoolean(theEnv,testResult); }
/********************************************************************* NAME : SlotExistPCommand DESCRIPTION : Determines if a slot is present in a class INPUTS : None RETURNS : True if the slot exists, false otherwise SIDE EFFECTS : None NOTES : H/L Syntax : (slot-existp <class> <slot> [inherit]) *********************************************************************/ void SlotExistPCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { Defclass *cls; SlotDescriptor *sd; bool inheritFlag = false; UDFValue theArg; sd = CheckSlotExists(context,"slot-existp",&cls,false,true); if (sd == NULL) { returnValue->lexemeValue = FalseSymbol(theEnv); return; } if (UDFHasNextArgument(context)) { if (! UDFNextArgument(context,SYMBOL_BIT,&theArg)) { return; } if (strcmp(theArg.lexemeValue->contents,"inherit") != 0) { UDFInvalidArgumentMessage(context,"keyword \"inherit\""); SetEvaluationError(theEnv,true); returnValue->lexemeValue = FalseSymbol(theEnv); return; } inheritFlag = true; } returnValue->lexemeValue = CreateBoolean(theEnv,((sd->cls == cls) ? true : inheritFlag)); }
TITANIUM_PROPERTY_GETTER(CoreDispatcher, HasThreadAccess) { auto value = unwrap()->HasThreadAccess; auto context = get_context(); auto result = context.CreateBoolean(value); return result; }
TITANIUM_FUNCTION(Properties, hasProperty) { ENSURE_STRING_AT_INDEX(property, 0); const auto js_context = this_object.get_context(); const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>(); return js_context.CreateBoolean(object_ptr->hasProperty(property)); }
TITANIUM_FUNCTION(Properties, getBool) { ENSURE_STRING_AT_INDEX(property, 0); ENSURE_OPTIONAL_BOOL_AT_INDEX(defaultValue, 1, false); const auto js_context = this_object.get_context(); const auto object_ptr = GetStaticObject(js_context).GetPrivate<Properties>(); return js_context.CreateBoolean(object_ptr->getBool(property, defaultValue)); }
/******************************************************** NAME : ClassExistPCommand DESCRIPTION : Determines if a class exists INPUTS : None RETURNS : True if class exists, false otherwise SIDE EFFECTS : None NOTES : H/L Syntax : (class-existp <arg>) ********************************************************/ void ClassExistPCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { UDFValue theArg; if (! UDFFirstArgument(context,SYMBOL_BIT,&theArg)) { return; } returnValue->lexemeValue = CreateBoolean(theEnv,((LookupDefclassByMdlOrScope(theEnv,theArg.lexemeValue->contents) != NULL) ? true : false)); }
void SDCCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { UDFValue theArg; returnValue->lexemeValue = CreateBoolean(theEnv,GetDynamicConstraintChecking(theEnv)); if (! UDFFirstArgument(context,ANY_TYPE_BITS,&theArg)) { return; } SetDynamicConstraintChecking(theEnv,theArg.value != FalseSymbol(theEnv)); }
TITANIUM_FUNCTION(File, append) { const auto js_context = this_object.get_context(); if (arguments.size() == 0) { return js_context.CreateUndefined(); } auto _0 = arguments.at(0); if (_0.IsString()) { return js_context.CreateBoolean(append(static_cast<std::string>(arguments.at(0)))); } else if (_0.IsObject()) { const auto js_object = static_cast<JSObject>(_0); const auto blob = js_object.GetPrivate<Titanium::Blob>(); const auto file = js_object.GetPrivate<File>(); if (blob != nullptr) { return js_context.CreateBoolean(append(blob)); } else if (file != nullptr) { return js_context.CreateBoolean(append(file)); } } return js_context.CreateNull(); }
/********************************************************************** NAME : SlotDirectAccessPCommand DESCRIPTION : Determines if an existing slot can be directly referenced by the class - i.e., if the slot is private, is the slot defined in the class INPUTS : None RETURNS : True if the slot is private, false otherwise SIDE EFFECTS : None NOTES : H/L Syntax : (slot-direct-accessp <class> <slot>) **********************************************************************/ void SlotDirectAccessPCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { Defclass *theDefclass; SlotDescriptor *sd; sd = CheckSlotExists(context,"slot-direct-accessp",&theDefclass,true,true); if (sd == NULL) { returnValue->lexemeValue = FalseSymbol(theEnv); } else { returnValue->lexemeValue = CreateBoolean(theEnv,((sd->publicVisibility || (sd->cls == theDefclass)) ? true : false)); } }
/********************************************************************** NAME : SlotInitablePCommand DESCRIPTION : Determines if an existing slot can be initialized via an init message-handler or slot-override INPUTS : None RETURNS : True if the slot is writable, false otherwise SIDE EFFECTS : None NOTES : H/L Syntax : (slot-initablep <class> <slot>) **********************************************************************/ void SlotInitablePCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { Defclass *theDefclass; SlotDescriptor *sd; sd = CheckSlotExists(context,"slot-initablep",&theDefclass,true,true); if (sd == NULL) { returnValue->lexemeValue = FalseSymbol(theEnv); } else { returnValue->lexemeValue = CreateBoolean(theEnv,(sd->noWrite && (sd->initializeOnly == 0)) ? false : true); } }
/********************************************************************* NAME : SubclassPCommand DESCRIPTION : Determines if a class is a subclass of another INPUTS : None RETURNS : True if class-1 is a subclass of class-2 SIDE EFFECTS : None NOTES : H/L Syntax : (subclassp <class-1> <class-2>) *********************************************************************/ void SubclassPCommand( Environment *theEnv, UDFContext *context, UDFValue *returnValue) { Defclass *c1, *c2; if (CheckTwoClasses(context,"subclassp",&c1,&c2) == false) { returnValue->lexemeValue = FalseSymbol(theEnv); return; } returnValue->lexemeValue = CreateBoolean(theEnv,SubclassP(c1,c2)); }
TITANIUM_FUNCTION(GeneralTransform, TryTransform) { auto context = get_context(); if (arguments.size() == 2) { auto _0 = arguments.at(0); TITANIUM_ASSERT_AND_THROW(_0.IsObject(), "Expected Object"); auto object_inPoint = static_cast<JSObject>(_0); ::Windows::Foundation::Point inPoint; // Assign fields explicitly since we didn't use a constructor auto object_inPoint_X = object_inPoint.GetProperty("X"); TITANIUM_ASSERT_AND_THROW(object_inPoint_X.IsNumber(), "Expected Number"); auto object_inPoint_X_ = static_cast<float>(static_cast<double>(object_inPoint_X)); inPoint.X = object_inPoint_X_; auto object_inPoint_Y = object_inPoint.GetProperty("Y"); TITANIUM_ASSERT_AND_THROW(object_inPoint_Y.IsNumber(), "Expected Number"); auto object_inPoint_Y_ = static_cast<float>(static_cast<double>(object_inPoint_Y)); inPoint.Y = object_inPoint_Y_; auto _1 = arguments.at(1); TITANIUM_ASSERT_AND_THROW(_1.IsObject(), "Expected Object"); auto object_outPoint = static_cast<JSObject>(_1); ::Windows::Foundation::Point outPoint; // Assign fields explicitly since we didn't use a constructor auto object_outPoint_X = object_outPoint.GetProperty("X"); TITANIUM_ASSERT_AND_THROW(object_outPoint_X.IsNumber(), "Expected Number"); auto object_outPoint_X_ = static_cast<float>(static_cast<double>(object_outPoint_X)); outPoint.X = object_outPoint_X_; auto object_outPoint_Y = object_outPoint.GetProperty("Y"); TITANIUM_ASSERT_AND_THROW(object_outPoint_Y.IsNumber(), "Expected Number"); auto object_outPoint_Y_ = static_cast<float>(static_cast<double>(object_outPoint_Y)); outPoint.Y = object_outPoint_Y_; auto method_result = unwrap()->TryTransform(inPoint, &outPoint); auto result = context.CreateBoolean(method_result); auto out_1 = context.CreateObject(); auto outPoint_X_ = context.CreateNumber(static_cast<double>(outPoint.X)); out_1.SetProperty("X", outPoint_X_); auto outPoint_Y_ = context.CreateNumber(static_cast<double>(outPoint.Y)); out_1.SetProperty("Y", outPoint_Y_); _1 = out_1; return result; } // Catch-all if no arg count matches! TITANIUM_LOG_DEBUG("No method signature matched GeneralTransform::TryTransform with # of args: ", arguments.size()); return context.CreateUndefined(); }