From 5d7704b9a87295aab4e9be343a913e08e576b0a0 Mon Sep 17 00:00:00 2001 From: Hrishabh Gupta Date: Wed, 23 Apr 2014 19:16:09 +0530 Subject: [PATCH 01/17] parse function updated --- lib/libphonenumber-execjs/libphonenumber.rb | 31 ++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/libphonenumber-execjs/libphonenumber.rb b/lib/libphonenumber-execjs/libphonenumber.rb index 0296752..bb9478f 100644 --- a/lib/libphonenumber-execjs/libphonenumber.rb +++ b/lib/libphonenumber-execjs/libphonenumber.rb @@ -15,7 +15,36 @@ def normalize(str="") end def parse(str="", default_region="ZZ") - context.call "i18n.phonenumbers.PhoneNumberUtil.getInstance().parse", str, default_region + #context.call "i18n.phonenumbers.PhoneNumberUtil.getInstance().parse", str, default_region + context.call '(function (a,b) { + try{ + var phoneUtil = i18n.phonenumbers.PhoneNumberUtil.getInstance(); + var number = phoneUtil.parseAndKeepRawInput(a, b); + var VR = i18n.phonenumbers.PhoneNumberUtil.ValidationResult; + var _r = phoneUtil.isPossibleNumberWithReason(number); + var _is_reason = null; + for(reason in VR){ + if (_r == VR[reason]){ + _is_reason = reason; + break; + } + } + return { + util: phoneUtil.parse(a,b), + country: phoneUtil.getRegionCodeForNumber(number), + type: phoneUtil.getNumberType(number), + e164_number: phoneUtil.format(number, 0), + is_possible_number: phoneUtil.isPossibleNumber(number), + validation_reasult: _is_reason + }; + }catch(e){ + return { + message: e, + error: true + } + } + }) + ', str, default_region end def simple From 0a16b8600aef2720e79acd0069c4bee97f330f40 Mon Sep 17 00:00:00 2001 From: Hrishabh Gupta Date: Wed, 23 Apr 2014 19:19:56 +0530 Subject: [PATCH 02/17] LibDate Updated --- support/libphonenumber.js | 8373 +++++++++++++++++++++++-------------- 1 file changed, 5193 insertions(+), 3180 deletions(-) diff --git a/support/libphonenumber.js b/support/libphonenumber.js index 890925a..a2caeb8 100644 --- a/support/libphonenumber.js +++ b/support/libphonenumber.js @@ -24,6 +24,8 @@ var CLOSURE_NO_DEPS = true; * global CLOSURE_NO_DEPS is set to true. This allows projects to * include their own deps file(s) from different locations. * + * + * @provideGoog */ @@ -35,13 +37,13 @@ var COMPILED = false; /** - * Base namespace for the Closure library. Checks to see goog is - * already defined in the current scope before assigning to prevent - * clobbering if base.js is loaded more than once. + * Base namespace for the Closure library. Checks to see goog is already + * defined in the current scope before assigning to prevent clobbering if + * base.js is loaded more than once. * * @const */ -var goog = goog || {}; // Identifies this file as the Closure base. +var goog = goog || {}; /** @@ -50,6 +52,114 @@ var goog = goog || {}; // Identifies this file as the Closure base. goog.global = this; +/** + * A hook for overriding the define values in uncompiled mode. + * + * In uncompiled mode, {@code CLOSURE_UNCOMPILED_DEFINES} may be defined before + * loading base.js. If a key is defined in {@code CLOSURE_UNCOMPILED_DEFINES}, + * {@code goog.define} will use the value instead of the default value. This + * allows flags to be overwritten without compilation (this is normally + * accomplished with the compiler's "define" flag). + * + * Example: + *
+ *   var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false};
+ * 
+ * + * @type {Object.|undefined} + */ +goog.global.CLOSURE_UNCOMPILED_DEFINES; + + +/** + * A hook for overriding the define values in uncompiled or compiled mode, + * like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In + * uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence. + * + * Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or + * string literals or the compiler will emit an error. + * + * While any @define value may be set, only those set with goog.define will be + * effective for uncompiled code. + * + * Example: + *
+ *   var CLOSURE_DEFINES = {'goog.DEBUG': false};
+ * 
+ * + * @type {Object.|undefined} + */ +goog.global.CLOSURE_DEFINES; + + +/** + * Builds an object structure for the provided namespace path, ensuring that + * names that already exist are not overwritten. For example: + * "a.b.c" -> a = {};a.b={};a.b.c={}; + * Used by goog.provide and goog.exportSymbol. + * @param {string} name name of the object that this file defines. + * @param {*=} opt_object the object to expose at the end of the path. + * @param {Object=} opt_objectToExportTo The object to add the path to; default + * is |goog.global|. + * @private + */ +goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { + var parts = name.split('.'); + var cur = opt_objectToExportTo || goog.global; + + // Internet Explorer exhibits strange behavior when throwing errors from + // methods externed in this manner. See the testExportSymbolExceptions in + // base_test.html for an example. + if (!(parts[0] in cur) && cur.execScript) { + cur.execScript('var ' + parts[0]); + } + + // Certain browsers cannot parse code in the form for((a in b); c;); + // This pattern is produced by the JSCompiler when it collapses the + // statement above into the conditional loop below. To prevent this from + // happening, use a for-loop and reserve the init logic as below. + + // Parentheses added to eliminate strict JS warning in Firefox. + for (var part; parts.length && (part = parts.shift());) { + if (!parts.length && opt_object !== undefined) { + // last part and we have an object; use it + cur[part] = opt_object; + } else if (cur[part]) { + cur = cur[part]; + } else { + cur = cur[part] = {}; + } + } +}; + + +/** + * Defines a named value. In uncompiled mode, the value is retreived from + * CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and + * has the property specified, and otherwise used the defined defaultValue. + * When compiled, the default can be overridden using compiler command-line + * options. + * + * @param {string} name The distinguished name to provide. + * @param {string|number|boolean} defaultValue + */ +goog.define = function(name, defaultValue) { + var value = defaultValue; + if (!COMPILED) { + if (goog.global.CLOSURE_UNCOMPILED_DEFINES && + Object.prototype.hasOwnProperty.call( + goog.global.CLOSURE_UNCOMPILED_DEFINES, name)) { + value = goog.global.CLOSURE_UNCOMPILED_DEFINES[name]; + } else if (goog.global.CLOSURE_DEFINES && + Object.prototype.hasOwnProperty.call( + goog.global.CLOSURE_DEFINES, name)) { + value = goog.global.CLOSURE_DEFINES[name]; + } + } + goog.exportPath_(name, value); +}; + + /** * @define {boolean} DEBUG is provided as a convenience so that debugging code * that should not be included in a production js_binary can be easily stripped @@ -80,13 +190,38 @@ goog.DEBUG = true; * this rule: the Hebrew language. For legacy reasons the old code (iw) should * be used instead of the new code (he), see http://wiki/Main/IIISynonyms. */ -goog.LOCALE = 'en'; // default to en +goog.define('goog.LOCALE', 'en'); // default to en + + +/** + * @define {boolean} Whether this code is running on trusted sites. + * + * On untrusted sites, several native functions can be defined or overridden by + * external libraries like Prototype, Datejs, and JQuery and setting this flag + * to false forces closure to use its own implementations when possible. + * + * If your JavaScript can be loaded by a third party site and you are wary about + * relying on non-standard implementations, specify + * "--define goog.TRUSTED_SITE=false" to the JSCompiler. + */ +goog.define('goog.TRUSTED_SITE', true); + + +/** + * @define {boolean} Whether a project is expected to be running in strict mode. + * + * This define can be used to trigger alternate implementations compatible with + * running in EcmaScript Strict mode or warn about unavailable functionality. + * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode + */ +goog.define('goog.STRICT_MODE_COMPATIBLE', false); /** * Creates object stubs for a namespace. The presence of one or more * goog.provide() calls indicate that the file defines the given - * objects/namespaces. Build tools also scan for provide/require statements + * objects/namespaces. Provided objects must not be null or undefined. + * Build tools also scan for provide/require statements * to discern dependencies, build dependency files (see deps.js), etc. * @see goog.require * @param {string} name Namespace provided by this file in the form @@ -120,6 +255,11 @@ goog.provide = function(name) { /** * Marks that the current file should only be used for testing, and never for * live code in production. + * + * In the case of unit tests, the message may optionally be an exact namespace + * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra + * provide (if not explicitly defined in the code). + * * @param {string=} opt_message Optional message to add to the error that's * raised when used in production code. */ @@ -132,6 +272,25 @@ goog.setTestOnly = function(opt_message) { }; +/** + * Forward declares a symbol. This is an indication to the compiler that the + * symbol may be used in the source yet is not required and may not be provided + * in compilation. + * + * The most common usage of forward declaration is code that takes a type as a + * function parameter but does not need to require it. By forward declaring + * instead of requiring, no hard dependency is made, and (if not required + * elsewhere) the namespace may never be required and thus, not be pulled + * into the JavaScript binary. If it is required elsewhere, it will be type + * checked as normal. + * + * + * @param {string} name The namespace to forward declare in the form of + * "goog.package.part". + */ +goog.forwardDeclare = function(name) {}; + + if (!COMPILED) { /** @@ -142,13 +301,14 @@ if (!COMPILED) { * @private */ goog.isProvided_ = function(name) { - return !goog.implicitNamespaces_[name] && !!goog.getObjectByName(name); + return !goog.implicitNamespaces_[name] && + goog.isDefAndNotNull(goog.getObjectByName(name)); }; /** * Namespaces implicitly defined by goog.provide. For example, - * goog.provide('goog.events.Event') implicitly declares - * that 'goog' and 'goog.events' must be namespaces. + * goog.provide('goog.events.Event') implicitly declares that 'goog' and + * 'goog.events' must be namespaces. * * @type {Object} * @private @@ -158,51 +318,10 @@ if (!COMPILED) { /** - * Builds an object structure for the provided namespace path, - * ensuring that names that already exist are not overwritten. For - * example: - * "a.b.c" -> a = {};a.b={};a.b.c={}; - * Used by goog.provide and goog.exportSymbol. - * @param {string} name name of the object that this file defines. - * @param {*=} opt_object the object to expose at the end of the path. - * @param {Object=} opt_objectToExportTo The object to add the path to; default - * is |goog.global|. - * @private - */ -goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { - var parts = name.split('.'); - var cur = opt_objectToExportTo || goog.global; - - // Internet Explorer exhibits strange behavior when throwing errors from - // methods externed in this manner. See the testExportSymbolExceptions in - // base_test.html for an example. - if (!(parts[0] in cur) && cur.execScript) { - cur.execScript('var ' + parts[0]); - } - - // Certain browsers cannot parse code in the form for((a in b); c;); - // This pattern is produced by the JSCompiler when it collapses the - // statement above into the conditional loop below. To prevent this from - // happening, use a for-loop and reserve the init logic as below. - - // Parentheses added to eliminate strict JS warning in Firefox. - for (var part; parts.length && (part = parts.shift());) { - if (!parts.length && goog.isDef(opt_object)) { - // last part and we have an object; use it - cur[part] = opt_object; - } else if (cur[part]) { - cur = cur[part]; - } else { - cur = cur[part] = {}; - } - } -}; - - -/** - * Returns an object based on its fully qualified external name. If you are - * using a compilation pass that renames property names beware that using this - * function will not find renamed properties. + * Returns an object based on its fully qualified external name. The object + * is not found if null or undefined. If you are using a compilation pass that + * renames property names beware that using this function will not find renamed + * properties. * * @param {string} name The fully qualified name. * @param {Object=} opt_obj The object within which to look; default is @@ -248,7 +367,7 @@ goog.globalize = function(obj, opt_global) { * this file requires. */ goog.addDependency = function(relPath, provides, requires) { - if (!COMPILED) { + if (goog.DEPENDENCIES_ENABLED) { var provide, require; var path = relPath.replace(/\\/g, '/'); var deps = goog.dependencies_; @@ -271,14 +390,14 @@ goog.addDependency = function(relPath, provides, requires) { -// NOTE(user): The debug DOM loader was included in base.js as an orignal -// way to do "debug-mode" development. The dependency system can sometimes -// be confusing, as can the debug DOM loader's asyncronous nature. +// NOTE(nnaze): The debug DOM loader was included in base.js as an original way +// to do "debug-mode" development. The dependency system can sometimes be +// confusing, as can the debug DOM loader's asynchronous nature. // -// With the DOM loader, a call to goog.require() is not blocking -- the -// script will not load until some point after the current script. If a -// namespace is needed at runtime, it needs to be defined in a previous -// script, or loaded via require() with its registered dependencies. +// With the DOM loader, a call to goog.require() is not blocking -- the script +// will not load until some point after the current script. If a namespace is +// needed at runtime, it needs to be defined in a previous script, or loaded via +// require() with its registered dependencies. // User-defined namespaces may need their own deps file. See http://go/js_deps, // http://go/genjsdeps, or, externally, DepsWriter. // http://code.google.com/closure/library/docs/depswriter.html @@ -299,26 +418,25 @@ goog.addDependency = function(relPath, provides, requires) { * provided (and depend on the fact that some outside tool correctly ordered * the script). */ -goog.ENABLE_DEBUG_LOADER = true; +goog.define('goog.ENABLE_DEBUG_LOADER', true); /** - * Implements a system for the dynamic resolution of dependencies - * that works in parallel with the BUILD system. Note that all calls - * to goog.require will be stripped by the JSCompiler when the - * --closure_pass option is used. + * Implements a system for the dynamic resolution of dependencies that works in + * parallel with the BUILD system. Note that all calls to goog.require will be + * stripped by the JSCompiler when the --closure_pass option is used. * @see goog.provide - * @param {string} name Namespace to include (as was given in goog.provide()) - * in the form "goog.package.part". + * @param {string} name Namespace to include (as was given in goog.provide()) in + * the form "goog.package.part". */ goog.require = function(name) { - // if the object already exists we do not need do do anything - // TODO(user): If we start to support require based on file name this has - // to change - // TODO(user): If we allow goog.foo.* this has to change - // TODO(user): If we implement dynamic load after page load we should probably - // not remove this code for the compiled output + // If the object already exists we do not need do do anything. + // TODO(arv): If we start to support require based on file name this has to + // change. + // TODO(arv): If we allow goog.foo.* this has to change. + // TODO(arv): If we implement dynamic load after page load we should probably + // not remove this code for the compiled output. if (!COMPILED) { if (goog.isProvided_(name)) { return; @@ -346,7 +464,7 @@ goog.require = function(name) { /** - * Path for included scripts + * Path for included scripts. * @type {string} */ goog.basePath = ''; @@ -360,8 +478,7 @@ goog.global.CLOSURE_BASE_PATH; /** - * Whether to write out Closure's deps file. By default, - * the deps are written. + * Whether to write out Closure's deps file. By default, the deps are written. * @type {boolean|undefined} */ goog.global.CLOSURE_NO_DEPS; @@ -375,6 +492,7 @@ goog.global.CLOSURE_NO_DEPS; * * The function is passed the script source, which is a relative URI. It should * return true if the script was imported, false otherwise. + * @type {(function(string): boolean)|undefined} */ goog.global.CLOSURE_IMPORT_SCRIPT; @@ -389,30 +507,29 @@ goog.nullFunction = function() {}; /** * The identity function. Returns its first argument. * - * @param {...*} var_args The arguments of the function. - * @return {*} The first argument. + * @param {*=} opt_returnValue The single value that will be returned. + * @param {...*} var_args Optional trailing arguments. These are ignored. + * @return {?} The first argument. We can't know the type -- just pass it along + * without type. * @deprecated Use goog.functions.identity instead. */ -goog.identityFunction = function(var_args) { - return arguments[0]; +goog.identityFunction = function(opt_returnValue, var_args) { + return opt_returnValue; }; /** * When defining a class Foo with an abstract method bar(), you can do: - * * Foo.prototype.bar = goog.abstractMethod * - * Now if a subclass of Foo fails to override bar(), an error - * will be thrown when bar() is invoked. + * Now if a subclass of Foo fails to override bar(), an error will be thrown + * when bar() is invoked. * - * Note: This does not take the name of the function to override as - * an argument because that would make it more difficult to obfuscate - * our JavaScript code. + * Note: This does not take the name of the function to override as an argument + * because that would make it more difficult to obfuscate our JavaScript code. * * @type {!Function} - * @throws {Error} when invoked to indicate the method should be - * overridden. + * @throws {Error} when invoked to indicate the method should be overridden. */ goog.abstractMethod = function() { throw Error('unimplemented abstract method'); @@ -420,22 +537,46 @@ goog.abstractMethod = function() { /** - * Adds a {@code getInstance} static method that always return the same instance - * object. + * Adds a {@code getInstance} static method that always returns the same + * instance object. * @param {!Function} ctor The constructor for the class to add the static * method to. */ goog.addSingletonGetter = function(ctor) { ctor.getInstance = function() { - return ctor.instance_ || (ctor.instance_ = new ctor()); + if (ctor.instance_) { + return ctor.instance_; + } + if (goog.DEBUG) { + // NOTE: JSCompiler can't optimize away Array#push. + goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor; + } + return ctor.instance_ = new ctor; }; }; -if (!COMPILED && goog.ENABLE_DEBUG_LOADER) { +/** + * All singleton classes that have been instantiated, for testing. Don't read + * it directly, use the {@code goog.testing.singleton} module. The compiler + * removes this variable if unused. + * @type {!Array.} + * @private + */ +goog.instantiatedSingletons_ = []; + + +/** + * True if goog.dependencies_ is available. + * @const {boolean} + */ +goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER; + + +if (goog.DEPENDENCIES_ENABLED) { /** - * Object used to keep track of urls that have already been added. This - * record allows the prevention of circular dependencies. + * Object used to keep track of urls that have already been added. This record + * allows the prevention of circular dependencies. * @type {Object} * @private */ @@ -444,7 +585,7 @@ if (!COMPILED && goog.ENABLE_DEBUG_LOADER) { /** * This object is used to keep track of dependencies and other data that is - * used for loading scripts + * used for loading scripts. * @private * @type {Object} */ @@ -452,10 +593,9 @@ if (!COMPILED && goog.ENABLE_DEBUG_LOADER) { pathToNames: {}, // 1 to many nameToPath: {}, // 1 to 1 requires: {}, // 1 to many - // used when resolving dependencies to prevent us from - // visiting the file twice + // Used when resolving dependencies to prevent us from visiting file twice. visited: {}, - written: {} // used to keep track of script files we have written + written: {} // Used to keep track of script files we have written. }; @@ -472,7 +612,7 @@ if (!COMPILED && goog.ENABLE_DEBUG_LOADER) { /** - * Tries to detect the base path of the base.js script that bootstraps Closure + * Tries to detect the base path of base.js script that bootstraps Closure. * @private */ goog.findBasePath_ = function() { @@ -524,6 +664,23 @@ if (!COMPILED && goog.ENABLE_DEBUG_LOADER) { goog.writeScriptTag_ = function(src) { if (goog.inHtmlDocument_()) { var doc = goog.global.document; + + // If the user tries to require a new symbol after document load, + // something has gone terribly wrong. Doing a document.write would + // wipe out the page. + if (doc.readyState == 'complete') { + // Certain test frameworks load base.js multiple times, which tries + // to write deps.js each time. If that happens, just fail silently. + // These frameworks wipe the page between each load of base.js, so this + // is OK. + var isDeps = /\bdeps.js$/.test(src); + if (isDeps) { + return false; + } else { + throw Error('Cannot write "' + src + '" after document load'); + } + } + doc.write( '