1 // Copyright (c) 2014 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var signature_to_type = { 'n': 'number',
15 Utils.prototype.validateArguments = function(signature, args) {
16 var full_args = Array.prototype.slice.call(args);
18 // After '?' everything is optional.
19 var mandatory_len = signature.indexOf('?') === -1 ? signature.length : signature.indexOf('?');
21 if (full_args.length < mandatory_len)
24 // Mandatory arguments.
25 for (var i = 0; i < mandatory_len; i++) {
26 if (typeof full_args[i] !== signature_to_type[signature[i]] || full_args[i] === null)
30 // Optional args may be null.
31 for (var i = mandatory_len; i < full_args.length && i < signature.length - 1; i++) {
32 if (full_args[i] !== null && typeof full_args[i] !== signature_to_type[signature[i + 1]])
39 Utils.prototype.validateObject = function(object, signature, attributes) {
40 for (var i = 0; i < signature.length; i++) {
41 if (object.hasOwnProperty(attributes[i]) &&
42 typeof object[attributes[i]] !== signature_to_type[signature[i]]) {
50 exports = new Utils();