delete priv;
}
-bool JSAlarmRelative::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception)
-{
- return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
-}
-
+
JSObjectRef DLL_EXPORT JSAlarmRelative::constructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
- try {
- ArgumentValidator validator(ctx, argumentCount, arguments);
+ ArgumentValidator validator(ctx, argumentCount, arguments);
+ AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative());
+
+ try {
long delay = validator.toLong(0);
- if (delay < 0) {
- throw InvalidValuesException("delay cannot be negative value");
- }
- long period = validator.toLong(1, true, 0);
- if (period < 0) {
- throw InvalidValuesException("period cannot be negative value");
- }
+ privateData->setDelay(delay);
- if ((argumentCount > 1) && !JSValueIsNull(ctx, arguments[1])) {
- return JSValueToObject(ctx, createJSObject(ctx, delay, period), exception);
- } else {
- return JSValueToObject(ctx, createJSObject(ctx, delay, -1), exception);
- }
- } catch (const BasePlatformException& err) {
- return JSWebAPIErrorFactory::postException(ctx, exception, err);
- }
+ long period = validator.toLong(1, true, -1);
+ privateData->setPeriod(period);
+
+ } catch (const BasePlatformException& err) {
+ LoggerE("Exception occured while creating constructor : " << err.getMessage());
+ }
+
+ JSAlarmRelativePriv *priv = new JSAlarmRelativePriv(ctx, privateData);
+ JSObjectRef obj = JSObjectMake(ctx, getClassRef(), priv);
+
+ JSStringRef ctorName = JSStringCreateWithUTF8CString("constructor");
+ JSObjectSetProperty(ctx, obj, ctorName, constructor,
+ kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete | kJSPropertyAttributeDontEnum, NULL);
+ JSStringRelease(ctorName);
+ return obj;
}
AlarmRelativePtr JSAlarmRelative::getPrivData(JSObjectRef object)