Initial method contains validation for mandatory and optional arguments.
'system_setting/system_setting.gyp:*',
'time/time.gyp:*',
'tizen/tizen.gyp:*',
+ 'utils/utils.gyp:*',
],
'conditions': [
[ 'tizen == 1', {
--- /dev/null
+{
+ 'includes':[
+ '../common/common.gypi',
+ ],
+ 'targets': [
+ {
+ 'target_name': 'tizen_utils',
+ 'type': 'loadable_module',
+ 'sources': [
+ 'utils_api.js',
+ 'utils_extension.cc',
+ 'utils_extension.h',
+ '../common/extension.cc',
+ '../common/extension.h',
+ ],
+ },
+ ],
+}
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var signature_to_type = { 'n': 'number',
+ 'f': 'function',
+ 'b': 'boolean',
+ 's': 'string',
+ 'o': 'object'
+ };
+
+function Utils() {
+}
+
+Utils.prototype.validateArguments = function(signature, args) {
+ var full_args = Array.prototype.slice.call(args);
+
+ // After '?' everything is optional.
+ var mandatory_len = signature.indexOf('?') === -1 ? signature.length : signature.indexOf('?');
+
+ if (full_args.length < mandatory_len)
+ return false;
+
+ // Mandatory arguments.
+ for (var i = 0; i < mandatory_len; i++) {
+ if (typeof full_args[i] !== signature_to_type[signature[i]] || full_args[i] === null)
+ return false;
+ }
+
+ // Optional args may be null.
+ for (var i = mandatory_len; i < full_args.length && i < signature.length - 1; i++) {
+ if (full_args[i] !== null && typeof full_args[i] !== signature_to_type[signature[i + 1]])
+ return false;
+ }
+
+ return true;
+};
+
+Utils.prototype.validateObject = function(object, signature, attributes) {
+ for (var i = 0; i < signature.length; i++) {
+ if (object.hasOwnProperty(attributes[i]) &&
+ typeof object[attributes[i]] !== signature_to_type[signature[i]]) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+exports = new Utils();
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "utils/utils_extension.h"
+
+// This will be generated from tizen_api.js.
+extern const char kSource_utils_api[];
+
+common::Extension* CreateExtension() {
+ return new UtilsExtension;
+}
+
+UtilsExtension::UtilsExtension() {
+ SetExtensionName("xwalk.utils");
+ SetJavaScriptAPI(kSource_utils_api);
+}
+
+UtilsExtension::~UtilsExtension() {}
--- /dev/null
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UTILS_UTILS_EXTENSION_H_
+#define UTILS_UTILS_EXTENSION_H_
+
+#include "common/extension.h"
+
+class UtilsExtension : public common::Extension {
+ public:
+ UtilsExtension();
+ virtual ~UtilsExtension();
+};
+
+#endif // UTILS_UTILS_EXTENSION_H_