Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Scalaxy/JS: moved code around

  • Loading branch information...
commit 14b047d36912da4b0f96b438e7e015c13d743d35 1 parent bf161d8
@ochafik ochafik authored
Showing with 7,023 additions and 398 deletions.
  1. 0  Experiments/JS/{ → Compiler}/src/main/javascript/experiments.js
  2. 0  Experiments/JS/{ → Compiler}/src/main/javascript/goog.base.js
  3. 0  Experiments/JS/{ → Compiler}/src/main/javascript/goog.deps.js
  4. 0  Experiments/JS/{ → Compiler}/src/main/javascript/mixins.js
  5. 0  Experiments/JS/{ → Compiler}/src/main/javascript/scalaxy.js
  6. 0  Experiments/JS/{ → Compiler}/src/main/javascript/scalaxy.lang.Class.js
  7. 0  Experiments/JS/{ → Compiler}/src/main/javascript/scalaxy.lang.Object.js
  8. 0  Experiments/JS/{ → Compiler}/src/main/javascript/scalaxy.lang.js
  9. 0  Experiments/JS/{ → Compiler}/src/main/javascript/scalaxy.lazy.js
  10. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/ast/JS.scala
  11. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/ast/PosAnnotatedString.scala
  12. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/ast/package.scala
  13. +1 −1  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/compiler/CrossCompiler.scala
  14. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/compiler/CrossCompilerComponent.scala
  15. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/ASTConverter.scala
  16. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/ApiMappings.scala
  17. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/JavaScript.scala
  18. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/Matchers.scala
  19. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/QuasiQuoteHacks.scala
  20. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/ScalaToJSTypeConversions.scala
  21. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/ScalaToJavaScriptConversion.scala
  22. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/ScalaToJavaScriptConverter.scala
  23. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/global.scala
  24. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/conversion/setters.scala
  25. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/runtime/DynamicValue.scala
  26. 0  Experiments/JS/{ → Compiler}/src/main/scala/scalaxy/js/runtime/Union.scala
  27. 0  Experiments/JS/{ → Compiler}/src/test/scala/scalaxy/js/Example.scala
  28. 0  Experiments/JS/{ → Compiler}/src/test/scala/scalaxy/js/Global.scala
  29. 0  Experiments/JS/{ → Compiler}/src/test/scala/scalaxy/js/JavaScriptTest.scala
  30. 0  Experiments/JS/{ → Compiler}/src/test/scala/scalaxy/js/MixinsTest.scala
  31. 0  Experiments/JS/{ → Compiler}/src/test/scala/scalaxy/js/Run.scala
  32. +12 −15 Experiments/JS/{ → Compiler}/src/test/scala/scalaxy/js/ast/JSTest.scala
  33. +39 −0 Experiments/JS/Core/src/main/javascript/experiments.js
  34. +1,607 −0 Experiments/JS/Core/src/main/javascript/goog.base.js
  35. +928 −0 Experiments/JS/Core/src/main/javascript/goog.deps.js
  36. +108 −0 Experiments/JS/Core/src/main/javascript/mixins.js
  37. +35 −0 Experiments/JS/Core/src/main/javascript/scalaxy.js
  38. +173 −0 Experiments/JS/Core/src/main/javascript/scalaxy.lang.Class.js
  39. +33 −0 Experiments/JS/Core/src/main/javascript/scalaxy.lang.Object.js
  40. +4 −0 Experiments/JS/Core/src/main/javascript/scalaxy.lang.js
  41. +60 −0 Experiments/JS/Core/src/main/javascript/scalaxy.lazy.js
  42. 0  Experiments/JS/{ → Core}/src/main/scala/scalaxy/js/package.scala
  43. +11 −0 Experiments/JS/Core/src/main/scala/scalaxy/js/runtime/DynamicValue.scala
  44. +13 −0 Experiments/JS/Core/src/main/scala/scalaxy/js/runtime/Union.scala
  45. +28 −0 Experiments/JS/Core/src/test/scala/scalaxy/js/MixinsTest.scala
  46. +39 −0 Experiments/JS/Generator/src/main/javascript/experiments.js
  47. +1,607 −0 Experiments/JS/Generator/src/main/javascript/goog.base.js
  48. +928 −0 Experiments/JS/Generator/src/main/javascript/goog.deps.js
  49. +108 −0 Experiments/JS/Generator/src/main/javascript/mixins.js
  50. +35 −0 Experiments/JS/Generator/src/main/javascript/scalaxy.js
  51. +173 −0 Experiments/JS/Generator/src/main/javascript/scalaxy.lang.Class.js
  52. +33 −0 Experiments/JS/Generator/src/main/javascript/scalaxy.lang.Object.js
  53. +4 −0 Experiments/JS/Generator/src/main/javascript/scalaxy.lang.js
  54. +60 −0 Experiments/JS/Generator/src/main/javascript/scalaxy.lazy.js
  55. +4 −8 ...iments/JS/{src/main/scala/scalaxy/js/Test.scala → Generator/src/main/scala/scalaxy/js/Generator.scala}
  56. +226 −0 Experiments/JS/Generator/src/main/scala/scalaxy/js/ast/JS.scala
  57. +29 −0 Experiments/JS/Generator/src/main/scala/scalaxy/js/ast/PosAnnotatedString.scala
  58. +9 −0 Experiments/JS/Generator/src/main/scala/scalaxy/js/ast/package.scala
  59. +36 −0 Experiments/JS/Generator/src/main/scala/scalaxy/js/externs/ClosureExterns.scala
  60. +11 −0 Experiments/JS/Generator/src/main/scala/scalaxy/js/externs/Externs.scala
  61. +22 −2 Experiments/JS/{ → Generator}/src/main/scala/scalaxy/js/externs/ExternsAnalysis.scala
  62. 0  Experiments/JS/{ → Generator}/src/main/scala/scalaxy/js/externs/JavaScriptExterns.scala
  63. +55 −0 Experiments/JS/Generator/src/main/scala/scalaxy/js/externs/JavaScriptToScalaSignaturesGenerator.scala
  64. 0  Experiments/JS/{ → Generator}/src/main/scala/scalaxy/js/externs/OptionalParam.scala
  65. 0  Experiments/JS/{ → Generator}/src/main/scala/scalaxy/js/externs/ScalaxyClosureUtils.scala
  66. +32 −0 Experiments/JS/Generator/src/main/scala/scalaxy/js/externs/SpecialCases.scala
  67. +386 −0 Experiments/JS/Generator/src/main/scala/scalaxy/js/externs/TreeGenerators.scala
  68. +61 −0 Experiments/JS/Generator/src/test/scala/scalaxy/js/ExternsTest.scala
  69. +50 −0 Experiments/JS/Generator/src/test/scala/scalaxy/js/Run.scala
  70. +63 −0 Experiments/JS/Generator/src/test/scala/scalaxy/js/ast/JSTest.scala
  71. +0 −19 Experiments/JS/src/main/scala/scalaxy/js/externs/ClosureExterns.scala
  72. +0 −101 Experiments/JS/src/main/scala/scalaxy/js/externs/JSToScalaTypeConversions.scala
  73. +0 −24 Experiments/JS/src/main/scala/scalaxy/js/externs/JavaScriptToScalaSignaturesGenerator.scala
  74. +0 −228 Experiments/JS/src/main/scala/scalaxy/js/externs/TreeGenerators.scala
View
0  ...nts/JS/src/main/javascript/experiments.js → ...mpiler/src/main/javascript/experiments.js
File renamed without changes
View
0  ...ments/JS/src/main/javascript/goog.base.js → ...Compiler/src/main/javascript/goog.base.js
File renamed without changes
View
0  ...ments/JS/src/main/javascript/goog.deps.js → ...Compiler/src/main/javascript/goog.deps.js
File renamed without changes
View
0  Experiments/JS/src/main/javascript/mixins.js → ...JS/Compiler/src/main/javascript/mixins.js
File renamed without changes
View
0  ...riments/JS/src/main/javascript/scalaxy.js → ...S/Compiler/src/main/javascript/scalaxy.js
File renamed without changes
View
0  ...src/main/javascript/scalaxy.lang.Class.js → ...src/main/javascript/scalaxy.lang.Class.js
File renamed without changes
View
0  ...rc/main/javascript/scalaxy.lang.Object.js → ...rc/main/javascript/scalaxy.lang.Object.js
File renamed without changes
View
0  ...ts/JS/src/main/javascript/scalaxy.lang.js → ...piler/src/main/javascript/scalaxy.lang.js
File renamed without changes
View
0  ...ts/JS/src/main/javascript/scalaxy.lazy.js → ...piler/src/main/javascript/scalaxy.lazy.js
File renamed without changes
View
0  ...JS/src/main/scala/scalaxy/js/ast/JS.scala → ...er/src/main/scala/scalaxy/js/ast/JS.scala
File renamed without changes
View
0  ...a/scalaxy/js/ast/PosAnnotatedString.scala → ...a/scalaxy/js/ast/PosAnnotatedString.scala
File renamed without changes
View
0  ...c/main/scala/scalaxy/js/ast/package.scala → ...c/main/scala/scalaxy/js/ast/package.scala
File renamed without changes
View
2  ...a/scalaxy/js/compiler/CrossCompiler.scala → ...a/scalaxy/js/compiler/CrossCompiler.scala
@@ -19,7 +19,7 @@ class CrossCompiler(outputDir: File, settings: Settings, reporter: Reporter)
//, new JSExportComponent(this) if full compilation + export is enabled
}
-object CrossCompiler extends App {
+object CrossCompiler { val args: Array[String] = Array()//extends App {
def findClassPath(c: Class[_]): Option[String] =
Option(c.getProtectionDomain.getCodeSource).map(_.getLocation.getFile)
View
0  .../js/compiler/CrossCompilerComponent.scala → .../js/compiler/CrossCompilerComponent.scala
File renamed without changes
View
0  .../scalaxy/js/conversion/ASTConverter.scala → .../scalaxy/js/conversion/ASTConverter.scala
File renamed without changes
View
0  ...a/scalaxy/js/conversion/ApiMappings.scala → ...a/scalaxy/js/conversion/ApiMappings.scala
File renamed without changes
View
0  ...la/scalaxy/js/conversion/JavaScript.scala → ...la/scalaxy/js/conversion/JavaScript.scala
File renamed without changes
View
0  ...cala/scalaxy/js/conversion/Matchers.scala → ...cala/scalaxy/js/conversion/Matchers.scala
File renamed without changes
View
0  ...alaxy/js/conversion/QuasiQuoteHacks.scala → ...alaxy/js/conversion/QuasiQuoteHacks.scala
File renamed without changes
View
0  ...conversion/ScalaToJSTypeConversions.scala → ...conversion/ScalaToJSTypeConversions.scala
File renamed without changes
View
0  ...version/ScalaToJavaScriptConversion.scala → ...version/ScalaToJavaScriptConversion.scala
File renamed without changes
View
0  ...nversion/ScalaToJavaScriptConverter.scala → ...nversion/ScalaToJavaScriptConverter.scala
File renamed without changes
View
0  .../scala/scalaxy/js/conversion/global.scala → .../scala/scalaxy/js/conversion/global.scala
File renamed without changes
View
0  ...scala/scalaxy/js/conversion/setters.scala → ...scala/scalaxy/js/conversion/setters.scala
File renamed without changes
View
0  ...ala/scalaxy/js/runtime/DynamicValue.scala → ...ala/scalaxy/js/runtime/DynamicValue.scala
File renamed without changes
View
0  ...main/scala/scalaxy/js/runtime/Union.scala → ...main/scala/scalaxy/js/runtime/Union.scala
File renamed without changes
View
0  ...S/src/test/scala/scalaxy/js/Example.scala → ...r/src/test/scala/scalaxy/js/Example.scala
File renamed without changes
View
0  ...JS/src/test/scala/scalaxy/js/Global.scala → ...er/src/test/scala/scalaxy/js/Global.scala
File renamed without changes
View
0  ...est/scala/scalaxy/js/JavaScriptTest.scala → ...est/scala/scalaxy/js/JavaScriptTest.scala
File renamed without changes
View
0  ...rc/test/scala/scalaxy/js/MixinsTest.scala → ...rc/test/scala/scalaxy/js/MixinsTest.scala
File renamed without changes
View
0  ...ts/JS/src/test/scala/scalaxy/js/Run.scala → ...piler/src/test/scala/scalaxy/js/Run.scala
File renamed without changes
View
27 ...rc/test/scala/scalaxy/js/ast/JSTest.scala → ...rc/test/scala/scalaxy/js/ast/JSTest.scala
@@ -17,24 +17,18 @@ class JSTest {
Function(
None,
List(
- Ident("a", pos)),
+ Ident("a")),
Block(
List(
Apply(
Select(
Select(
- Ident("window", pos),
- Ident("console", pos),
- pos),
- Literal("log", pos),
- pos),
+ Ident("window"),
+ Ident("console")),
+ Literal("log")),
List(
Literal(
- "foo\nbar'yo",
- pos)),
- pos)),
- pos),
- pos)).value
+ "foo\nbar'yo"))))))).value
)
}
@@ -45,10 +39,13 @@ class JSTest {
prettyPrint(
JSONObject(
Map(
- "a" -> JSONArray(List(Literal(1, pos), Literal(2, pos)), pos),
- "x" -> Literal(1, pos),
- "y" -> Literal("blah", pos)),
- pos)).value)
+ "a" -> JSONArray(List(Literal(1), Literal(2))),
+ "x" -> Literal(1),
+ "y" -> Literal("blah")
+ )
+ )
+ ).value
+ )
}
// @Test
View
39 Experiments/JS/Core/src/main/javascript/experiments.js
@@ -0,0 +1,39 @@
+goog.require("scalaxy.lang.Class");
+goog.require("scalaxy.lang.Object");
+
+
+/*
+package test
+class Test(val x: Int) [extends AnyRef] {
+ def blah = println("blah " + x)
+
+ println("Constructing Test with x = " + x)
+}
+*/
+
+if (!test) var test = {};
+
+/**
+ * @constructor
+ * @extends {scalaxy.lang.Object}
+ * @param {number} x
+ */
+test.Test = function(x) {
+ goog.base(this);
+ this.x = x;
+ window.console.log('Constructing Test with x = ' + this.x)
+};
+goog.inherits(test.Test, scalaxy.lang.Object);
+
+scalaxy.lang.Class.defineClass({
+ name: "test.Test",
+ constructor: test.Test,
+ base: scalaxy.lang.Object
+});
+
+/**
+ * @this {!test.Test}
+ */
+test.Test.prototype.blah = function() {
+ window.console.log('blah ' + this.x)
+};
View
1,607 Experiments/JS/Core/src/main/javascript/goog.base.js
@@ -0,0 +1,1607 @@
+// Copyright 2006 The Closure Library Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS-IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+/**
+ * @fileoverview Bootstrap for the Google JS Library (Closure).
+ *
+ * In uncompiled mode base.js will write out Closure's deps file, unless the
+ * global <code>CLOSURE_NO_DEPS</code> is set to true. This allows projects to
+ * include their own deps file(s) from different locations.
+ *
+ *
+ * @provideGoog
+ */
+
+
+/**
+ * @define {boolean} Overridden to true by the compiler when --closure_pass
+ * or --mark_as_compiled is specified.
+ */
+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.
+ *
+ * @const
+ */
+var goog = goog || {};
+
+
+/**
+ * Reference to the global context. In most cases this will be 'window'.
+ */
+goog.global = this;
+
+
+/**
+ * A hook for overriding the define values in uncompiled mode.
+ *
+ * In uncompiled mode, {@code CLOSURE_DEFINES} may be defined before loading
+ * base.js. If a key is defined in {@code CLOSURE_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:
+ * <pre>
+ * var CLOSURE_DEFINES = {'goog.DEBUG', false};
+ * </pre>
+ *
+ * @type {Object.<string, (string|number|boolean)>|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 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_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
+ * by specifying --define goog.DEBUG=false to the JSCompiler. For example, most
+ * toString() methods should be declared inside an "if (goog.DEBUG)" conditional
+ * because they are generally used for debugging purposes and it is difficult
+ * for the JSCompiler to statically determine whether they are used.
+ */
+goog.DEBUG = true;
+
+
+/**
+ * @define {string} LOCALE defines the locale being used for compilation. It is
+ * used to select locale specific data to be compiled in js binary. BUILD rule
+ * can specify this value by "--define goog.LOCALE=<locale_name>" as JSCompiler
+ * option.
+ *
+ * Take into account that the locale code format is important. You should use
+ * the canonical Unicode format with hyphen as a delimiter. Language must be
+ * lowercase, Language Script - Capitalized, Region - UPPERCASE.
+ * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN.
+ *
+ * See more info about locale codes here:
+ * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers
+ *
+ * For language codes you should use values defined by ISO 693-1. See it here
+ * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from
+ * 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.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);
+
+
+/**
+ * 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
+ * to discern dependencies, build dependency files (see deps.js), etc.
+ * @see goog.require
+ * @param {string} name Namespace provided by this file in the form
+ * "goog.package.part".
+ */
+goog.provide = function(name) {
+ if (!COMPILED) {
+ // Ensure that the same namespace isn't provided twice. This is intended
+ // to teach new developers that 'goog.provide' is effectively a variable
+ // declaration. And when JSCompiler transforms goog.provide into a real
+ // variable declaration, the compiled JS should work the same as the raw
+ // JS--even when the raw JS uses goog.provide incorrectly.
+ if (goog.isProvided_(name)) {
+ throw Error('Namespace "' + name + '" already declared.');
+ }
+ delete goog.implicitNamespaces_[name];
+
+ var namespace = name;
+ while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) {
+ if (goog.getObjectByName(namespace)) {
+ break;
+ }
+ goog.implicitNamespaces_[namespace] = true;
+ }
+ }
+
+ goog.exportPath_(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.
+ */
+goog.setTestOnly = function(opt_message) {
+ if (COMPILED && !goog.DEBUG) {
+ opt_message = opt_message || '';
+ throw Error('Importing test-only code into non-debug environment' +
+ opt_message ? ': ' + opt_message : '.');
+ }
+};
+
+
+if (!COMPILED) {
+
+ /**
+ * Check if the given name has been goog.provided. This will return false for
+ * names that are available only as implicit namespaces.
+ * @param {string} name name of the object to look for.
+ * @return {boolean} Whether the name has been provided.
+ * @private
+ */
+ goog.isProvided_ = function(name) {
+ return !goog.implicitNamespaces_[name] && !!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.
+ *
+ * @type {Object}
+ * @private
+ */
+ goog.implicitNamespaces_ = {};
+}
+
+
+/**
+ * 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.
+ *
+ * @param {string} name The fully qualified name.
+ * @param {Object=} opt_obj The object within which to look; default is
+ * |goog.global|.
+ * @return {?} The value (object or primitive) or, if not found, null.
+ */
+goog.getObjectByName = function(name, opt_obj) {
+ var parts = name.split('.');
+ var cur = opt_obj || goog.global;
+ for (var part; part = parts.shift(); ) {
+ if (goog.isDefAndNotNull(cur[part])) {
+ cur = cur[part];
+ } else {
+ return null;
+ }
+ }
+ return cur;
+};
+
+
+/**
+ * Globalizes a whole namespace, such as goog or goog.lang.
+ *
+ * @param {Object} obj The namespace to globalize.
+ * @param {Object=} opt_global The object to add the properties to.
+ * @deprecated Properties may be explicitly exported to the global scope, but
+ * this should no longer be done in bulk.
+ */
+goog.globalize = function(obj, opt_global) {
+ var global = opt_global || goog.global;
+ for (var x in obj) {
+ global[x] = obj[x];
+ }
+};
+
+
+/**
+ * Adds a dependency from a file to the files it requires.
+ * @param {string} relPath The path to the js file.
+ * @param {Array} provides An array of strings with the names of the objects
+ * this file provides.
+ * @param {Array} requires An array of strings with the names of the objects
+ * this file requires.
+ */
+goog.addDependency = function(relPath, provides, requires) {
+ if (goog.DEPENDENCIES_ENABLED) {
+ var provide, require;
+ var path = relPath.replace(/\\/g, '/');
+ var deps = goog.dependencies_;
+ for (var i = 0; provide = provides[i]; i++) {
+ deps.nameToPath[provide] = path;
+ if (!(path in deps.pathToNames)) {
+ deps.pathToNames[path] = {};
+ }
+ deps.pathToNames[path][provide] = true;
+ }
+ for (var j = 0; require = requires[j]; j++) {
+ if (!(path in deps.requires)) {
+ deps.requires[path] = {};
+ }
+ deps.requires[path][require] = true;
+ }
+ }
+};
+
+
+
+
+// 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.
+// 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
+//
+// Because of legacy clients, the DOM loader can't be easily removed from
+// base.js. Work is being done to make it disableable or replaceable for
+// different environments (DOM-less JavaScript interpreters like Rhino or V8,
+// for example). See bootstrap/ for more information.
+
+
+/**
+ * @define {boolean} Whether to enable the debug loader.
+ *
+ * If enabled, a call to goog.require() will attempt to load the namespace by
+ * appending a script tag to the DOM (if the namespace has been registered).
+ *
+ * If disabled, goog.require() will simply assert that the namespace has been
+ * provided (and depend on the fact that some outside tool correctly ordered
+ * the script).
+ */
+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.
+ * @see goog.provide
+ * @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(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;
+ }
+
+ if (goog.ENABLE_DEBUG_LOADER) {
+ var path = goog.getPathFromDeps_(name);
+ if (path) {
+ goog.included_[path] = true;
+ goog.writeScripts_();
+ return;
+ }
+ }
+
+ var errorMessage = 'goog.require could not find: ' + name;
+ if (goog.global.console) {
+ goog.global.console['error'](errorMessage);
+ }
+
+
+ throw Error(errorMessage);
+
+ }
+};
+
+
+/**
+ * Path for included scripts.
+ * @type {string}
+ */
+goog.basePath = '';
+
+
+/**
+ * A hook for overriding the base path.
+ * @type {string|undefined}
+ */
+goog.global.CLOSURE_BASE_PATH;
+
+
+/**
+ * Whether to write out Closure's deps file. By default, the deps are written.
+ * @type {boolean|undefined}
+ */
+goog.global.CLOSURE_NO_DEPS;
+
+
+/**
+ * A function to import a single script. This is meant to be overridden when
+ * Closure is being run in non-HTML contexts, such as web workers. It's defined
+ * in the global scope so that it can be set before base.js is loaded, which
+ * allows deps.js to be imported properly.
+ *
+ * The function is passed the script source, which is a relative URI. It should
+ * return true if the script was imported, false otherwise.
+ */
+goog.global.CLOSURE_IMPORT_SCRIPT;
+
+
+/**
+ * Null function used for default values of callbacks, etc.
+ * @return {void} Nothing.
+ */
+goog.nullFunction = function() {};
+
+
+/**
+ * The identity function. Returns its 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(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.
+ *
+ * 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.
+ */
+goog.abstractMethod = function() {
+ throw Error('unimplemented abstract method');
+};
+
+
+/**
+ * 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() {
+ 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;
+ };
+};
+
+
+/**
+ * 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.<!Function>}
+ * @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.
+ * @type {Object}
+ * @private
+ */
+ goog.included_ = {};
+
+
+ /**
+ * This object is used to keep track of dependencies and other data that is
+ * used for loading scripts.
+ * @private
+ * @type {Object}
+ */
+ goog.dependencies_ = {
+ pathToNames: {}, // 1 to many
+ nameToPath: {}, // 1 to 1
+ requires: {}, // 1 to many
+ // Used when resolving dependencies to prevent us from visiting file twice.
+ visited: {},
+ written: {} // Used to keep track of script files we have written.
+ };
+
+
+ /**
+ * Tries to detect whether is in the context of an HTML document.
+ * @return {boolean} True if it looks like HTML document.
+ * @private
+ */
+ goog.inHtmlDocument_ = function() {
+ var doc = goog.global.document;
+ return typeof doc != 'undefined' &&
+ 'write' in doc; // XULDocument misses write.
+ };
+
+
+ /**
+ * Tries to detect the base path of base.js script that bootstraps Closure.
+ * @private
+ */
+ goog.findBasePath_ = function() {
+ if (goog.global.CLOSURE_BASE_PATH) {
+ goog.basePath = goog.global.CLOSURE_BASE_PATH;
+ return;
+ } else if (!goog.inHtmlDocument_()) {
+ return;
+ }
+ var doc = goog.global.document;
+ var scripts = doc.getElementsByTagName('script');
+ // Search backwards since the current script is in almost all cases the one
+ // that has base.js.
+ for (var i = scripts.length - 1; i >= 0; --i) {
+ var src = scripts[i].src;
+ var qmark = src.lastIndexOf('?');
+ var l = qmark == -1 ? src.length : qmark;
+ if (src.substr(l - 7, 7) == 'base.js') {
+ goog.basePath = src.substr(0, l - 7);
+ return;
+ }
+ }
+ };
+
+
+ /**
+ * Imports a script if, and only if, that script hasn't already been imported.
+ * (Must be called at execution time)
+ * @param {string} src Script source.
+ * @private
+ */
+ goog.importScript_ = function(src) {
+ var importScript = goog.global.CLOSURE_IMPORT_SCRIPT ||
+ goog.writeScriptTag_;
+ if (!goog.dependencies_.written[src] && importScript(src)) {
+ goog.dependencies_.written[src] = true;
+ }
+ };
+
+
+ /**
+ * The default implementation of the import function. Writes a script tag to
+ * import the script.
+ *
+ * @param {string} src The script source.
+ * @return {boolean} True if the script was imported, false otherwise.
+ * @private
+ */
+ 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(
+ '<script type="text/javascript" src="' + src + '"></' + 'script>');
+ return true;
+ } else {
+ return false;
+ }
+ };
+
+
+ /**
+ * Resolves dependencies based on the dependencies added using addDependency
+ * and calls importScript_ in the correct order.
+ * @private
+ */
+ goog.writeScripts_ = function() {
+ // The scripts we need to write this time.
+ var scripts = [];
+ var seenScript = {};
+ var deps = goog.dependencies_;
+
+ function visitNode(path) {
+ if (path in deps.written) {
+ return;
+ }
+
+ // We have already visited this one. We can get here if we have cyclic
+ // dependencies.
+ if (path in deps.visited) {
+ if (!(path in seenScript)) {
+ seenScript[path] = true;
+ scripts.push(path);
+ }
+ return;
+ }
+
+ deps.visited[path] = true;
+
+ if (path in deps.requires) {
+ for (var requireName in deps.requires[path]) {
+ // If the required name is defined, we assume that it was already
+ // bootstrapped by other means.
+ if (!goog.isProvided_(requireName)) {
+ if (requireName in deps.nameToPath) {
+ visitNode(deps.nameToPath[requireName]);
+ } else {
+ throw Error('Undefined nameToPath for ' + requireName);
+ }
+ }
+ }
+ }
+
+ if (!(path in seenScript)) {
+ seenScript[path] = true;
+ scripts.push(path);
+ }
+ }
+
+ for (var path in goog.included_) {
+ if (!deps.written[path]) {
+ visitNode(path);
+ }
+ }
+
+ for (var i = 0; i < scripts.length; i++) {
+ if (scripts[i]) {
+ goog.importScript_(goog.basePath + scripts[i]);
+ } else {
+ throw Error('Undefined script input');
+ }
+ }
+ };
+
+
+ /**
+ * Looks at the dependency rules and tries to determine the script file that
+ * fulfills a particular rule.
+ * @param {string} rule In the form goog.namespace.Class or project.script.
+ * @return {?string} Url corresponding to the rule, or null.
+ * @private
+ */
+ goog.getPathFromDeps_ = function(rule) {
+ if (rule in goog.dependencies_.nameToPath) {
+ return goog.dependencies_.nameToPath[rule];
+ } else {
+ return null;
+ }
+ };
+
+ goog.findBasePath_();
+
+ // Allow projects to manage the deps files themselves.
+ if (!goog.global.CLOSURE_NO_DEPS) {
+ goog.importScript_(goog.basePath + 'deps.js');
+ }
+}
+
+
+
+//==============================================================================
+// Language Enhancements
+//==============================================================================
+
+
+/**
+ * This is a "fixed" version of the typeof operator. It differs from the typeof
+ * operator in such a way that null returns 'null' and arrays return 'array'.
+ * @param {*} value The value to get the type of.
+ * @return {string} The name of the type.
+ */
+goog.typeOf = function(value) {
+ var s = typeof value;
+ if (s == 'object') {
+ if (value) {
+ // Check these first, so we can avoid calling Object.prototype.toString if
+ // possible.
+ //
+ // IE improperly marshals tyepof across execution contexts, but a
+ // cross-context object will still return false for "instanceof Object".
+ if (value instanceof Array) {
+ return 'array';
+ } else if (value instanceof Object) {
+ return s;
+ }
+
+ // HACK: In order to use an Object prototype method on the arbitrary
+ // value, the compiler requires the value be cast to type Object,
+ // even though the ECMA spec explicitly allows it.
+ var className = Object.prototype.toString.call(
+ /** @type {Object} */ (value));
+ // In Firefox 3.6, attempting to access iframe window objects' length
+ // property throws an NS_ERROR_FAILURE, so we need to special-case it
+ // here.
+ if (className == '[object Window]') {
+ return 'object';
+ }
+
+ // We cannot always use constructor == Array or instanceof Array because
+ // different frames have different Array objects. In IE6, if the iframe
+ // where the array was created is destroyed, the array loses its
+ // prototype. Then dereferencing val.splice here throws an exception, so
+ // we can't use goog.isFunction. Calling typeof directly returns 'unknown'
+ // so that will work. In this case, this function will return false and
+ // most array functions will still work because the array is still
+ // array-like (supports length and []) even though it has lost its
+ // prototype.
+ // Mark Miller noticed that Object.prototype.toString
+ // allows access to the unforgeable [[Class]] property.
+ // 15.2.4.2 Object.prototype.toString ( )
+ // When the toString method is called, the following steps are taken:
+ // 1. Get the [[Class]] property of this object.
+ // 2. Compute a string value by concatenating the three strings
+ // "[object ", Result(1), and "]".
+ // 3. Return Result(2).
+ // and this behavior survives the destruction of the execution context.
+ if ((className == '[object Array]' ||
+ // In IE all non value types are wrapped as objects across window
+ // boundaries (not iframe though) so we have to do object detection
+ // for this edge case.
+ typeof value.length == 'number' &&
+ typeof value.splice != 'undefined' &&
+ typeof value.propertyIsEnumerable != 'undefined' &&
+ !value.propertyIsEnumerable('splice')
+
+ )) {
+ return 'array';
+ }
+ // HACK: There is still an array case that fails.
+ // function ArrayImpostor() {}
+ // ArrayImpostor.prototype = [];
+ // var impostor = new ArrayImpostor;
+ // this can be fixed by getting rid of the fast path
+ // (value instanceof Array) and solely relying on
+ // (value && Object.prototype.toString.vall(value) === '[object Array]')
+ // but that would require many more function calls and is not warranted
+ // unless closure code is receiving objects from untrusted sources.
+
+ // IE in cross-window calls does not correctly marshal the function type
+ // (it appears just as an object) so we cannot use just typeof val ==
+ // 'function'. However, if the object has a call property, it is a
+ // function.
+ if ((className == '[object Function]' ||
+ typeof value.call != 'undefined' &&
+ typeof value.propertyIsEnumerable != 'undefined' &&
+ !value.propertyIsEnumerable('call'))) {
+ return 'function';
+ }
+
+ } else {
+ return 'null';
+ }
+
+ } else if (s == 'function' && typeof value.call == 'undefined') {
+ // In Safari typeof nodeList returns 'function', and on Firefox typeof
+ // behaves similarly for HTML{Applet,Embed,Object}, Elements and RegExps. We
+ // would like to return object for those and we can detect an invalid
+ // function by making sure that the function object has a call method.
+ return 'object';
+ }
+ return s;
+};
+
+
+/**
+ * Returns true if the specified value is not undefined.
+ * WARNING: Do not use this to test if an object has a property. Use the in
+ * operator instead. Additionally, this function assumes that the global
+ * undefined variable has not been redefined.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is defined.
+ */
+goog.isDef = function(val) {
+ return val !== undefined;
+};
+
+
+/**
+ * Returns true if the specified value is null.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is null.
+ */
+goog.isNull = function(val) {
+ return val === null;
+};
+
+
+/**
+ * Returns true if the specified value is defined and not null.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is defined and not null.
+ */
+goog.isDefAndNotNull = function(val) {
+ // Note that undefined == null.
+ return val != null;
+};
+
+
+/**
+ * Returns true if the specified value is an array.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is an array.
+ */
+goog.isArray = function(val) {
+ return goog.typeOf(val) == 'array';
+};
+
+
+/**
+ * Returns true if the object looks like an array. To qualify as array like
+ * the value needs to be either a NodeList or an object with a Number length
+ * property.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is an array.
+ */
+goog.isArrayLike = function(val) {
+ var type = goog.typeOf(val);
+ return type == 'array' || type == 'object' && typeof val.length == 'number';
+};
+
+
+/**
+ * Returns true if the object looks like a Date. To qualify as Date-like the
+ * value needs to be an object and have a getFullYear() function.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is a like a Date.
+ */
+goog.isDateLike = function(val) {
+ return goog.isObject(val) && typeof val.getFullYear == 'function';
+};
+
+
+/**
+ * Returns true if the specified value is a string.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is a string.
+ */
+goog.isString = function(val) {
+ return typeof val == 'string';
+};
+
+
+/**
+ * Returns true if the specified value is a boolean.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is boolean.
+ */
+goog.isBoolean = function(val) {
+ return typeof val == 'boolean';
+};
+
+
+/**
+ * Returns true if the specified value is a number.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is a number.
+ */
+goog.isNumber = function(val) {
+ return typeof val == 'number';
+};
+
+
+/**
+ * Returns true if the specified value is a function.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is a function.
+ */
+goog.isFunction = function(val) {
+ return goog.typeOf(val) == 'function';
+};
+
+
+/**
+ * Returns true if the specified value is an object. This includes arrays and
+ * functions.
+ * @param {*} val Variable to test.
+ * @return {boolean} Whether variable is an object.
+ */
+goog.isObject = function(val) {
+ var type = typeof val;
+ return type == 'object' && val != null || type == 'function';
+ // return Object(val) === val also works, but is slower, especially if val is
+ // not an object.
+};
+
+
+/**
+ * Gets a unique ID for an object. This mutates the object so that further calls
+ * with the same object as a parameter returns the same value. The unique ID is
+ * guaranteed to be unique across the current session amongst objects that are
+ * passed into {@code getUid}. There is no guarantee that the ID is unique or
+ * consistent across sessions. It is unsafe to generate unique ID for function
+ * prototypes.
+ *
+ * @param {Object} obj The object to get the unique ID for.
+ * @return {number} The unique ID for the object.
+ */
+goog.getUid = function(obj) {
+ // TODO(arv): Make the type stricter, do not accept null.
+
+ // In Opera window.hasOwnProperty exists but always returns false so we avoid
+ // using it. As a consequence the unique ID generated for BaseClass.prototype
+ // and SubClass.prototype will be the same.
+ return obj[goog.UID_PROPERTY_] ||
+ (obj[goog.UID_PROPERTY_] = ++goog.uidCounter_);
+};
+
+
+/**
+ * Whether the given object is alreay assigned a unique ID.
+ *
+ * This does not modify the object.
+ *
+ * @param {Object} obj The object to check.
+ * @return {boolean} Whether there an assigned unique id for the object.
+ */
+goog.hasUid = function(obj) {
+ return !!obj[goog.UID_PROPERTY_];
+};
+
+
+/**
+ * Removes the unique ID from an object. This is useful if the object was
+ * previously mutated using {@code goog.getUid} in which case the mutation is
+ * undone.
+ * @param {Object} obj The object to remove the unique ID field from.
+ */
+goog.removeUid = function(obj) {
+ // TODO(arv): Make the type stricter, do not accept null.
+
+ // In IE, DOM nodes are not instances of Object and throw an exception if we
+ // try to delete. Instead we try to use removeAttribute.
+ if ('removeAttribute' in obj) {
+ obj.removeAttribute(goog.UID_PROPERTY_);
+ }
+ /** @preserveTry */
+ try {
+ delete obj[goog.UID_PROPERTY_];
+ } catch (ex) {
+ }
+};
+
+
+/**
+ * Name for unique ID property. Initialized in a way to help avoid collisions
+ * with other closure JavaScript on the same page.
+ * @type {string}
+ * @private
+ */
+goog.UID_PROPERTY_ = 'closure_uid_' + ((Math.random() * 1e9) >>> 0);
+
+
+/**
+ * Counter for UID.
+ * @type {number}
+ * @private
+ */
+goog.uidCounter_ = 0;
+
+
+/**
+ * Adds a hash code field to an object. The hash code is unique for the
+ * given object.
+ * @param {Object} obj The object to get the hash code for.
+ * @return {number} The hash code for the object.
+ * @deprecated Use goog.getUid instead.
+ */
+goog.getHashCode = goog.getUid;
+
+
+/**
+ * Removes the hash code field from an object.
+ * @param {Object} obj The object to remove the field from.
+ * @deprecated Use goog.removeUid instead.
+ */
+goog.removeHashCode = goog.removeUid;
+
+
+/**
+ * Clones a value. The input may be an Object, Array, or basic type. Objects and
+ * arrays will be cloned recursively.
+ *
+ * WARNINGS:
+ * <code>goog.cloneObject</code> does not detect reference loops. Objects that
+ * refer to themselves will cause infinite recursion.
+ *
+ * <code>goog.cloneObject</code> is unaware of unique identifiers, and copies
+ * UIDs created by <code>getUid</code> into cloned results.
+ *
+ * @param {*} obj The value to clone.
+ * @return {*} A clone of the input value.
+ * @deprecated goog.cloneObject is unsafe. Prefer the goog.object methods.
+ */
+goog.cloneObject = function(obj) {
+ var type = goog.typeOf(obj);
+ if (type == 'object' || type == 'array') {
+ if (obj.clone) {
+ return obj.clone();
+ }
+ var clone = type == 'array' ? [] : {};
+ for (var key in obj) {
+ clone[key] = goog.cloneObject(obj[key]);
+ }
+ return clone;
+ }
+
+ return obj;
+};
+
+
+/**
+ * A native implementation of goog.bind.
+ * @param {Function} fn A function to partially apply.
+ * @param {Object|undefined} selfObj Specifies the object which this should
+ * point to when the function is run.
+ * @param {...*} var_args Additional arguments that are partially applied to the
+ * function.
+ * @return {!Function} A partially-applied form of the function bind() was
+ * invoked as a method of.
+ * @private
+ * @suppress {deprecated} The compiler thinks that Function.prototype.bind is
+ * deprecated because some people have declared a pure-JS version.
+ * Only the pure-JS version is truly deprecated.
+ */
+goog.bindNative_ = function(fn, selfObj, var_args) {
+ return /** @type {!Function} */ (fn.call.apply(fn.bind, arguments));
+};
+
+
+/**
+ * A pure-JS implementation of goog.bind.
+ * @param {Function} fn A function to partially apply.
+ * @param {Object|undefined} selfObj Specifies the object which this should
+ * point to when the function is run.
+ * @param {...*} var_args Additional arguments that are partially applied to the
+ * function.
+ * @return {!Function} A partially-applied form of the function bind() was
+ * invoked as a method of.
+ * @private
+ */
+goog.bindJs_ = function(fn, selfObj, var_args) {
+ if (!fn) {
+ throw new Error();
+ }
+
+ if (arguments.length > 2) {
+ var boundArgs = Array.prototype.slice.call(arguments, 2);
+ return function() {
+ // Prepend the bound arguments to the current arguments.
+ var newArgs = Array.prototype.slice.call(arguments);
+ Array.prototype.unshift.apply(newArgs, boundArgs);
+ return fn.apply(selfObj, newArgs);
+ };
+
+ } else {
+ return function() {
+ return fn.apply(selfObj, arguments);
+ };
+ }
+};
+
+
+/**
+ * Partially applies this function to a particular 'this object' and zero or
+ * more arguments. The result is a new function with some arguments of the first
+ * function pre-filled and the value of this 'pre-specified'.
+ *
+ * Remaining arguments specified at call-time are appended to the pre-specified
+ * ones.
+ *
+ * Also see: {@link #partial}.
+ *
+ * Usage:
+ * <pre>var barMethBound = bind(myFunction, myObj, 'arg1', 'arg2');
+ * barMethBound('arg3', 'arg4');</pre>
+ *
+ * @param {?function(this:T, ...)} fn A function to partially apply.
+ * @param {T} selfObj Specifies the object which this should point to when the
+ * function is run.
+ * @param {...*} var_args Additional arguments that are partially applied to the
+ * function.
+ * @return {!Function} A partially-applied form of the function bind() was
+ * invoked as a method of.
+ * @template T
+ * @suppress {deprecated} See above.
+ */
+goog.bind = function(fn, selfObj, var_args) {
+ // TODO(nicksantos): narrow the type signature.
+ if (Function.prototype.bind &&
+ // NOTE(nicksantos): Somebody pulled base.js into the default Chrome
+ // extension environment. This means that for Chrome extensions, they get
+ // the implementation of Function.prototype.bind that calls goog.bind
+ // instead of the native one. Even worse, we don't want to introduce a
+ // circular dependency between goog.bind and Function.prototype.bind, so
+ // we have to hack this to make sure it works correctly.
+ Function.prototype.bind.toString().indexOf('native code') != -1) {
+ goog.bind = goog.bindNative_;
+ } else {
+ goog.bind = goog.bindJs_;
+ }
+ return goog.bind.apply(null, arguments);
+};
+
+
+/**
+ * Like bind(), except that a 'this object' is not required. Useful when the
+ * target function is already bound.
+ *
+ * Usage:
+ * var g = partial(f, arg1, arg2);
+ * g(arg3, arg4);
+ *
+ * @param {Function} fn A function to partially apply.
+ * @param {...*} var_args Additional arguments that are partially applied to fn.
+ * @return {!Function} A partially-applied form of the function bind() was
+ * invoked as a method of.
+ */
+goog.partial = function(fn, var_args) {
+ var args = Array.prototype.slice.call(arguments, 1);
+ return function() {
+ // Clone the array (with slice()) and append additional arguments
+ // to the existing arguments.
+ var newArgs = args.slice();
+ newArgs.push.apply(newArgs, arguments);
+ return fn.apply(this, newArgs);
+ };
+};
+
+
+/**
+ * Copies all the members of a source object to a target object. This method
+ * does not work on all browsers for all objects that contain keys such as
+ * toString or hasOwnProperty. Use goog.object.extend for this purpose.
+ * @param {Object} target Target.
+ * @param {Object} source Source.
+ */
+goog.mixin = function(target, source) {
+ for (var x in source) {
+ target[x] = source[x];
+ }
+
+ // For IE7 or lower, the for-in-loop does not contain any properties that are
+ // not enumerable on the prototype object (for example, isPrototypeOf from
+ // Object.prototype) but also it will not include 'replace' on objects that
+ // extend String and change 'replace' (not that it is common for anyone to
+ // extend anything except Object).
+};
+
+
+/**
+ * @return {number} An integer value representing the number of milliseconds
+ * between midnight, January 1, 1970 and the current time.
+ */
+goog.now = (goog.TRUSTED_SITE && Date.now) || (function() {
+ // Unary plus operator converts its operand to a number which in the case of
+ // a date is done by calling getTime().
+ return +new Date();
+});
+
+
+/**
+ * Evals JavaScript in the global scope. In IE this uses execScript, other
+ * browsers use goog.global.eval. If goog.global.eval does not evaluate in the
+ * global scope (for example, in Safari), appends a script tag instead.
+ * Throws an exception if neither execScript or eval is defined.
+ * @param {string} script JavaScript string.
+ */
+goog.globalEval = function(script) {
+ if (goog.global.execScript) {
+ goog.global.execScript(script, 'JavaScript');
+ } else if (goog.global.eval) {
+ // Test to see if eval works
+ if (goog.evalWorksForGlobals_ == null) {
+ goog.global.eval('var _et_ = 1;');
+ if (typeof goog.global['_et_'] != 'undefined') {
+ delete goog.global['_et_'];
+ goog.evalWorksForGlobals_ = true;
+ } else {
+ goog.evalWorksForGlobals_ = false;
+ }
+ }
+
+ if (goog.evalWorksForGlobals_) {
+ goog.global.eval(script);
+ } else {
+ var doc = goog.global.document;
+ var scriptElt = doc.createElement('script');
+ scriptElt.type = 'text/javascript';
+ scriptElt.defer = false;
+ // Note(user): can't use .innerHTML since "t('<test>')" will fail and
+ // .text doesn't work in Safari 2. Therefore we append a text node.
+ scriptElt.appendChild(doc.createTextNode(script));
+ doc.body.appendChild(scriptElt);
+ doc.body.removeChild(scriptElt);
+ }
+ } else {
+ throw Error('goog.globalEval not available');
+ }
+};
+
+
+/**
+ * Indicates whether or not we can call 'eval' directly to eval code in the
+ * global scope. Set to a Boolean by the first call to goog.globalEval (which
+ * empirically tests whether eval works for globals). @see goog.globalEval
+ * @type {?boolean}
+ * @private
+ */
+goog.evalWorksForGlobals_ = null;
+
+
+/**
+ * Optional map of CSS class names to obfuscated names used with
+ * goog.getCssName().
+ * @type {Object|undefined}
+ * @private
+ * @see goog.setCssNameMapping
+ */
+goog.cssNameMapping_;
+
+
+/**
+ * Optional obfuscation style for CSS class names. Should be set to either
+ * 'BY_WHOLE' or 'BY_PART' if defined.
+ * @type {string|undefined}
+ * @private
+ * @see goog.setCssNameMapping
+ */
+goog.cssNameMappingStyle_;
+
+
+/**
+ * Handles strings that are intended to be used as CSS class names.
+ *
+ * This function works in tandem with @see goog.setCssNameMapping.
+ *
+ * Without any mapping set, the arguments are simple joined with a hyphen and
+ * passed through unaltered.
+ *
+ * When there is a mapping, there are two possible styles in which these
+ * mappings are used. In the BY_PART style, each part (i.e. in between hyphens)
+ * of the passed in css name is rewritten according to the map. In the BY_WHOLE
+ * style, the full css name is looked up in the map directly. If a rewrite is
+ * not specified by the map, the compiler will output a warning.
+ *
+ * When the mapping is passed to the compiler, it will replace calls to
+ * goog.getCssName with the strings from the mapping, e.g.
+ * var x = goog.getCssName('foo');
+ * var y = goog.getCssName(this.baseClass, 'active');
+ * becomes:
+ * var x= 'foo';
+ * var y = this.baseClass + '-active';
+ *
+ * If one argument is passed it will be processed, if two are passed only the
+ * modifier will be processed, as it is assumed the first argument was generated
+ * as a result of calling goog.getCssName.
+ *
+ * @param {string} className The class name.
+ * @param {string=} opt_modifier A modifier to be appended to the class name.
+ * @return {string} The class name or the concatenation of the class name and
+ * the modifier.
+ */
+goog.getCssName = function(className, opt_modifier) {
+ var getMapping = function(cssName) {
+ return goog.cssNameMapping_[cssName] || cssName;
+ };
+
+ var renameByParts = function(cssName) {
+ // Remap all the parts individually.
+ var parts = cssName.split('-');
+ var mapped = [];
+ for (var i = 0; i < parts.length; i++) {
+ mapped.push(getMapping(parts[i]));
+ }
+ return mapped.join('-');
+ };
+
+ var rename;
+ if (goog.cssNameMapping_) {
+ rename = goog.cssNameMappingStyle_ == 'BY_WHOLE' ?
+ getMapping : renameByParts;
+ } else {
+ rename = function(a) {
+ return a;
+ };
+ }
+
+ if (opt_modifier) {
+ return className + '-' + rename(opt_modifier);
+ } else {
+ return rename(className);
+ }
+};
+
+
+/**
+ * Sets the map to check when returning a value from goog.getCssName(). Example:
+ * <pre>
+ * goog.setCssNameMapping({
+ * "goog": "a",
+ * "disabled": "b",
+ * });
+ *
+ * var x = goog.getCssName('goog');
+ * // The following evaluates to: "a a-b".
+ * goog.getCssName('goog') + ' ' + goog.getCssName(x, 'disabled')
+ * </pre>
+ * When declared as a map of string literals to string literals, the JSCompiler
+ * will replace all calls to goog.getCssName() using the supplied map if the
+ * --closure_pass flag is set.
+ *
+ * @param {!Object} mapping A map of strings to strings where keys are possible
+ * arguments to goog.getCssName() and values are the corresponding values
+ * that should be returned.
+ * @param {string=} opt_style The style of css name mapping. There are two valid
+ * options: 'BY_PART', and 'BY_WHOLE'.
+ * @see goog.getCssName for a description.
+ */
+goog.setCssNameMapping = function(mapping, opt_style) {
+ goog.cssNameMapping_ = mapping;
+ goog.cssNameMappingStyle_ = opt_style;
+};
+
+
+/**
+ * To use CSS renaming in compiled mode, one of the input files should have a
+ * call to goog.setCssNameMapping() with an object literal that the JSCompiler
+ * can extract and use to replace all calls to goog.getCssName(). In uncompiled
+ * mode, JavaScript code should be loaded before this base.js file that declares
+ * a global variable, CLOSURE_CSS_NAME_MAPPING, which is used below. This is
+ * to ensure that the mapping is loaded before any calls to goog.getCssName()
+ * are made in uncompiled mode.
+ *
+ * A hook for overriding the CSS name mapping.
+ * @type {Object|undefined}
+ */
+goog.global.CLOSURE_CSS_NAME_MAPPING;
+
+
+if (!COMPILED && goog.global.CLOSURE_CSS_NAME_MAPPING) {
+ // This does not call goog.setCssNameMapping() because the JSCompiler
+ // requires that goog.setCssNameMapping() be called with an object literal.
+ goog.cssNameMapping_ = goog.global.CLOSURE_CSS_NAME_MAPPING;
+}
+
+
+/**
+ * Gets a localized message.
+ *
+ * This function is a compiler primitive. If you give the compiler a localized
+ * message bundle, it will replace the string at compile-time with a localized
+ * version, and expand goog.getMsg call to a concatenated string.
+ *
+ * Messages must be initialized in the form:
+ * <code>
+ * var MSG_NAME = goog.getMsg('Hello {$placeholder}', {'placeholder': 'world'});
+ * </code>
+ *
+ * @param {string} str Translatable string, places holders in the form {$foo}.
+ * @param {Object=} opt_values Map of place holder name to value.
+ * @return {string} message with placeholders filled.
+ */
+goog.getMsg = function(str, opt_values) {
+ var values = opt_values || {};
+ for (var key in values) {
+ var value = ('' + values[key]).replace(/\$/g, '$$$$');
+ str = str.replace(new RegExp('\\{\\$' + key + '\\}', 'gi'), value);
+ }
+ return str;
+};
+
+
+/**
+ * Gets a localized message. If the message does not have a translation, gives a
+ * fallback message.
+ *
+ * This is useful when introducing a new message that has not yet been
+ * translated into all languages.
+ *
+ * This function is a compiler primtive. Must be used in the form:
+ * <code>var x = goog.getMsgWithFallback(MSG_A, MSG_B);</code>
+ * where MSG_A and MSG_B were initialized with goog.getMsg.
+ *
+ * @param {string} a The preferred message.
+ * @param {string} b The fallback message.
+ * @return {string} The best translated message.
+ */
+goog.getMsgWithFallback = function(a, b) {
+ return a;
+};
+
+
+/**
+ * Exposes an unobfuscated global namespace path for the given object.
+ * Note that fields of the exported object *will* be obfuscated, unless they are
+ * exported in turn via this function or goog.exportProperty.
+ *
+ * Also handy for making public items that are defined in anonymous closures.
+ *
+ * ex. goog.exportSymbol('public.path.Foo', Foo);
+ *
+ * ex. goog.exportSymbol('public.path.Foo.staticFunction', Foo.staticFunction);
+ * public.path.Foo.staticFunction();
+ *
+ * ex. goog.exportSymbol('public.path.Foo.prototype.myMethod',
+ * Foo.prototype.myMethod);
+ * new public.path.Foo().myMethod();
+ *
+ * @param {string} publicPath Unobfuscated name to export.
+ * @param {*} object Object the name should point to.
+ * @param {Object=} opt_objectToExportTo The object to add the path to; default
+ * is goog.global.
+ */
+goog.exportSymbol = function(publicPath, object, opt_objectToExportTo) {
+ goog.exportPath_(publicPath, object, opt_objectToExportTo);
+};
+
+
+/**
+ * Exports a property unobfuscated into the object's namespace.
+ * ex. goog.exportProperty(Foo, 'staticFunction', Foo.staticFunction);
+ * ex. goog.exportProperty(Foo.prototype, 'myMethod', Foo.prototype.myMethod);
+ * @param {Object} object Object whose static property is being exported.
+ * @param {string} publicName Unobfuscated name to export.
+ * @param {*} symbol Object the name should point to.
+ */
+goog.exportProperty = function(object, publicName, symbol) {
+ object[publicName] = symbol;
+};
+
+
+/**
+ * Inherit the prototype methods from one constructor into another.
+ *
+ * Usage:
+ * <pre>
+ * function ParentClass(a, b) { }
+ * ParentClass.prototype.foo = function(a) { }
+ *
+ * function ChildClass(a, b, c) {
+ * goog.base(this, a, b);
+ * }
+ * goog.inherits(ChildClass, ParentClass);
+ *
+ * var child = new ChildClass('a', 'b', 'see');
+ * child.foo(); // This works.
+ * </pre>
+ *
+ * In addition, a superclass' implementation of a method can be invoked as
+ * follows:
+ *
+ * <pre>
+ * ChildClass.prototype.foo = function(a) {
+ * ChildClass.superClass_.foo.call(this, a);
+ * // Other code here.
+ * };
+ * </pre>
+ *
+ * @param {Function} childCtor Child class.
+ * @param {Function} parentCtor Parent class.
+ */
+goog.inherits = function(childCtor, parentCtor) {
+ /** @constructor */
+ function tempCtor() {};
+ tempCtor.prototype = parentCtor.prototype;
+ childCtor.superClass_ = parentCtor.prototype;
+ childCtor.prototype = new tempCtor();
+ /** @override */
+ childCtor.prototype.constructor = childCtor;
+};
+
+
+/**
+ * Call up to the superclass.
+ *
+ * If this is called from a constructor, then this calls the superclass
+ * contsructor with arguments 1-N.
+ *
+ * If this is called from a prototype method, then you must pass the name of the
+ * method as the second argument to this function. If you do not, you will get a
+ * runtime error. This calls the superclass' method with arguments 2-N.
+ *
+ * This function only works if you use goog.inherits to express inheritance
+ * relationships between your classes.
+ *
+ * This function is a compiler primitive. At compile-time, the compiler will do
+ * macro expansion to remove a lot of the extra overhead that this function
+ * introduces. The compiler will also enforce a lot of the assumptions that this
+ * function makes, and treat it as a compiler error if you break them.
+ *
+ * @param {!Object} me Should always be "this".
+ * @param {*=} opt_methodName The method name if calling a super method.
+ * @param {...*} var_args The rest of the arguments.
+ * @return {*} The return value of the superclass method.
+ */
+goog.base = function(me, opt_methodName, var_args) {
+ var caller = arguments.callee.caller;
+
+ if (goog.DEBUG) {
+ if (!caller) {
+ throw Error('arguments.caller not defined. goog.base() expects not ' +
+ 'to be running in strict mode. See ' +
+ 'http://www.ecma-international.org/ecma-262/5.1/#sec-C');
+ }
+ }
+
+ if (caller.superClass_) {
+ // This is a constructor. Call the superclass constructor.
+ return caller.superClass_.constructor.apply(
+ me, Array.prototype.slice.call(arguments, 1));
+ }
+
+ var args = Array.prototype.slice.call(arguments, 2);
+ var foundCaller = false;
+ for (var ctor = me.constructor;
+ ctor; ctor = ctor.superClass_ && ctor.superClass_.constructor) {
+ if (ctor.prototype[opt_methodName] === caller) {
+ foundCaller = true;
+ } else if (foundCaller) {
+ return ctor.prototype[opt_methodName].apply(me, args);
+ }
+ }
+
+ // If we did not find the caller in the prototype chain, then one of two
+ // things happened:
+ // 1) The caller is an instance method.
+ // 2) This method was not called by the right caller.
+ if (me[opt_methodName] === caller) {
+ return me.constructor.prototype[opt_methodName].apply(me, args);
+ } else {
+ throw Error(
+ 'goog.base called from a method of one name ' +
+ 'to a method of a different name');
+ }
+};
+
+
+/**
+ * Allow for aliasing within scope functions. This function exists for
+ * uncompiled code - in compiled code the calls will be inlined and the aliases
+ * applied. In uncompiled code the function is simply run since the aliases as
+ * written are valid JavaScript.
+ * @param {function()} fn Function to call. This function can contain aliases
+ * to namespaces (e.g. "var dom = goog.dom") or classes
+ * (e.g. "var Timer = goog.Timer").
+ */
+goog.scope = function(fn) {
+ fn.call(goog.global);
+};
+
+
View
928 Experiments/JS/Core/src/main/javascript/goog.deps.js
928 additions, 0 deletions not shown
View
108 Experiments/JS/Core/src/main/javascript/mixins.js
@@ -0,0 +1,108 @@
+goog.require('scalaxy.lang.Class');
+goog.require('scalaxy.lang.Object');
+
+//goog.require('goog.assert');
+
+/*
+ trait A { def foo = "A" }
+ trait B { def foo = "B" }
+
+ class MixedA extends A
+ class MixedSuperA extends A { override def foo = "super = " + super.foo }
+ class MixedSuperAB_A extends A with B { override def foo = "super = " + super[A].foo }
+ class MixedSuperAB_B extends A with B { override def foo = "super = " + super[B].foo }
+
+ assertEquals("A",
+ (new A {}).foo)
+
+ assertEquals("super = A",
+ (new A { override def foo = "super = " + super.foo }).foo)
+
+ assertEquals("C",
+ (new A with B { override def foo = "C" }).foo)
+
+ assertEquals("super = A",
+ (new A with B { override def foo = "super = " + super[A].foo }).foo)
+
+ assertEquals("super = B",
+ (new A with B { override def foo = "super = " + super[B].foo }).foo)
+*/
+
+/** @interface */
+var A = function() {};
+/**
+ * @this {A}
+ * @return {string}
+ */
+A.prototype.foo = function() {};
+/** @type {function(): string} */
+A.foo = function() { return "A"; };
+scalaxy.lang.Class.defineClass({ name: "A", constructor: A });
+
+/** @interface */
+var B = function() {};
+/**
+ * @this {B}
+ * @return {string}
+ */
+B.prototype.foo = function() {};
+/** @type {function(): string} */
+B.foo = function() { return "B"; };
+scalaxy.lang.Class.defineClass({ name: "B", constructor: B });
+
+/**
+ * @constructor
+ * @extends {scalaxy.lang.Object}
+ * @implements {A}
+ */
+var mixedA = function() {
+ goog.base(this);
+};
+goog.inherits(mixedA, scalaxy.lang.Object);
+scalaxy.lang.Class.defineClass({
+ name: "mixedA",
+ constructor: mixedA,
+ traits: [A],
+ base: scalaxy.lang.Object
+});
+
+/**
+ * @this {mixedA}
+ * @return {string}
+ */
+mixedA.prototype.foo = A.foo;
+
+/**
+ * @constructor
+ * @extends {scalaxy.lang.Object}
+ * @implements {A}
+ * @implements {B}
+ */
+var mixedAB = function() {
+ goog.base(this);
+};
+goog.inherits(mixedAB, scalaxy.lang.Object);
+scalaxy.lang.Class.defineClass({
+ name: "mixedAB",
+ constructor: mixedAB,
+ traits: [A, B],
+ base: scalaxy.lang.Object
+});
+
+/**
+ * @this {mixedAB}
+ * @return {string}
+ */
+mixedAB.prototype.foo = function() {
+ return "super = " + A.foo.apply(this, []);
+};
+
+var ma = new mixedA()
+window.console.log(ma.foo());
+window.console.log('ma.isInstanceOf(A) = ' + ma.isInstanceOf(scalaxy.lang.Class.forName('A')));
+window.console.log('ma.isInstanceOf(B) = ' + ma.isInstanceOf(scalaxy.lang.Class.forName('B')));
+
+var mab = new mixedAB()
+window.console.log(mab.foo());
+window.console.log('mab.isInstanceOf(A) = ' + mab.isInstanceOf(scalaxy.lang.Class.forName('A')));
+window.console.log('mab.isInstanceOf(B) = ' + mab.isInstanceOf(scalaxy.lang.Class.forName('B')));
View
35 Experiments/JS/Core/src/main/javascript/scalaxy.js
@@ -0,0 +1,35 @@
+goog.provide('scalaxy');
+
+var scalaxy = {};
+
+scalaxy.CLASS_FIELD = '$class$';
+scalaxy.COMPANION = '$companion$';
+
+/**
+ * Define a lazy final property (scala object or lazy val).
+ *
+ * @param {!Object} obj Object on which the property is defined.
+ * @param {string} name Name of the property.
+ * @param {function(): Object} builder Function that builds the property value.
+ */
+scalaxy.defineLazyFinalProperty = function(obj, name, builder) {
+ Object.defineProperty(obj, name, {
+ configurable: true,
+ enumerable: true,
+ get: function() {
+ var value = builder();
+ Object.defineProperty(obj, name, {
+ configurable: false,
+ enumerable: true,
+ value: value
+ });
+ return value;
+ }
+ });
+};
+
+/** @constructor */
+scalaxy.Tuple = function() {
+ this.values = arguments;
+};
+
View
173 Experiments/JS/Core/src/main/javascript/scalaxy.lang.Class.js
@@ -0,0 +1,173 @@
+goog.provide('scalaxy.lang.Class');
+goog.require('scalaxy.lang');
+goog.require('scalaxy.lang.Object');
+
+/**
+ * @typedef {{
+ * name: string,
+ * constructor: Function,
+ * base: (Object|undefined),
+ * traits: (Array.<Function>|undefined),
+ * module: (scalaxy.lang.Class|undefined)
+ * }}
+ */
+scalaxy.lang.ClassDescriptor;
+
+/**
+ * Runtime representation of a Java / Scala class.
+ *
+ * @constructor
+ * @param {scalaxy.lang.ClassDescriptor} desc Descriptor of the class in JSON form.
+ */
+scalaxy.lang.Class = function(desc) {
+
+ /** @type {string} */
+ this.name = desc.name;
+
+ /** @type {Function} */
+ this.constructor = desc.constructor;
+
+ /** @type {Object} */
+ this.base = desc.base || null;
+
+ /** @type {scalaxy.lang.Class|undefined} */
+ this.superclass_;
+
+ /** @type {Array.<Function>} */
+ this.traits = desc.traits || [];
+ this.traits.forEach(function(t) {
+ if (t instanceof scalaxy.lang.Object)
+ throw new Error("Not a trait: " + t);
+ })
+
+ /** @type {scalaxy.lang.Class} */
+ this.moduleClass = desc.module || null;
+};
+
+/**
+ * @this {!scalaxy.lang.Class}
+ * @return {string}
+ */
+scalaxy.lang.Class.prototype.getName = function() {
+ return this.name;
+};
+
+/**
+ * @this {!scalaxy.lang.Class}
+ * @return {string}
+ */
+scalaxy.lang.Class.prototype.getSimpleName = function() {
+ return this.name.split('.').splice(-1)[0];
+};
+
+/**
+ * @this {!scalaxy.lang.Class}
+ * @return {scalaxy.lang.Class}
+ */
+scalaxy.lang.Class.prototype.getSuperclass = function() {
+ if (this.base) {
+ this.superclass_ = this.base[scalaxy.CLASS_FIELD] || null;
+ }
+ return this.superclass_;
+};
+
+/**
+ * @this {!scalaxy.lang.Class}
+ * @return {boolean}
+ */
+scalaxy.lang.Class.prototype.isTrait = function() {
+ // TODO: better define this?
+ return !(this.constructor instanceof scalaxy.lang.Object);
+};
+
+/**
+ * @this {!scalaxy.lang.Class}
+ * @return {boolean}
+ */
+scalaxy.lang.Class.prototype.isModule = function() {
+ // TODO: better define this?
+ return !this.isTrait() && !goog.isDef(this.constructor.prototype);
+};
+
+/**
+ * @this {!scalaxy.lang.Class}
+ * @param {scalaxy.lang.Object} obj
+ * @return {boolean}
+ */
+scalaxy.lang.Class.prototype.isInstance = function(obj) {
+ if (!obj) {
+ return false;
+ }
+
+ if (this.isTrait()) {
+ var cls = obj.getClass();
+ while (cls) {
+ if (cls.traits.indexOf(this.constructor) >= 0) {
+ return true;
+ }
+ cls = cls.getSuperclass();
+ }
+ return false;
+ } else {
+ return obj instanceof this.constructor
+ }
+};
+
+/**
+ * Class declarations
+ *
+ * @private
+ */
+scalaxy.lang.Class.classes_ = {};
+
+/**
+ * Declare a class
+ *
+ * @param {!scalaxy.lang.ClassDescriptor} desc
+ * @return {!scalaxy.lang.Class}
+ */
+scalaxy.lang.Class.defineClass = function(desc) {
+ var cls = new scalaxy.lang.Class(desc);
+
+ Object.defineProperty(scalaxy.lang.Class.classes_, cls.getName(), {
+ value: cls,
+ enumerable: true
+ });
+
+ if (goog.isDefAndNotNull(cls.moduleClass)) {
+ scalaxy.defineLazyFinalProperty(
+ /** @type {!Object} */ (cls.constructor),
+ scalaxy.COMPANION,
+ /** @type {function()} */ (cls.moduleClass.constructor));
+ }
+ cls.constructor.prototype[scalaxy.CLASS_FIELD] = cls;
+ return cls;
+};
+
+scalaxy.lang.Class.forName = function(name) {
+ var cls = scalaxy.lang.Class.classes_[name];
+ if (!cls) {
+ throw new Error("ClassNotFoundException: " + name)
+ }
+ return cls;
+};
+
+/**
+ * Equivalent to `classOf[type]` in Scala.
+ *
+ * @param {!Function} type
+ */
+scalaxy.lang.Class.classOf = function(type) {
+ var cls = type[scalaxy.CLASS_FIELD];
+ if (cls instanceof scalaxy.lang.Class) {
+ return cls;
+ }
+ throw new Error("Not found: type " + type)
+}
+
+/** Shortcut */
+scalaxy.lang.Class.Object = scalaxy.lang.Class.defineClass({
+ name: "scalaxy.lang.Object",
+ constructor: scalaxy.lang.Object,
+ lazyBase: function() { return Object; }
+});
View
33 Experiments/JS/Core/src/main/javascript/scalaxy.lang.Object.js
@@ -0,0 +1,33 @@
+goog.provide('scalaxy.lang.Object');
+goog.require('scalaxy.lang');
+
+/**
+ * All Scala classes must derive from this.
+ *
+ * @constructor
+ */
+scalaxy.lang.Object = function() {
+ var cls = this.getClass();
+ // Call trait constructors on this.
+ cls.traits.forEach(function(t) { t.apply(this); }, this);
+};
+goog.inherits(scalaxy.lang.Object, Object);
+
+/**
+ * Equivalent to `obj.isInstanceOf[type]` in Scala.
+ *
+ * @this {!scalaxy.lang.Object}
+ * @param {!scalaxy.lang.Class} type
+ * @return {boolean}
+ */
+scalaxy.lang.Object.prototype.isInstanceOf = function(type) {
+ return type.isInstance(this);
+};
+
+/**
+ * @this {!scalaxy.lang.Object}
+ * @return {!scalaxy.lang.Class}
+ */
+scalaxy.lang.Object.prototype.getClass = function() {
+ return this[scalaxy.CLASS_FIELD];
+};
View
4 Experiments/JS/Core/src/main/javascript/scalaxy.lang.js
@@ -0,0 +1,4 @@
+goog.provide("scalaxy.lang");
+goog.require("scalaxy");
+
+scalaxy.lang = {};
View
60 Experiments/JS/Core/src/main/javascript/scalaxy.lazy.js
@@ -0,0 +1,60 @@
+goog.provide('scalaxy.lazy');
+goog.require('scalaxy');
+
+scalaxy.lazy = {};
+
+/**
+ * @type {Object}
+ * @private
+ */
+scalaxy.lazy.builders_ = {};
+
+/**
+ * @type {Object}
+ * @private
+ */
+scalaxy.lazy.values_ = {};
+
+/**
+ * @param {string} fullName
+ * @param {!Object} owner
+ * @param {string} name
+ * @param {function(): Object} builder
+ */
+scalaxy.lazy.declareLazy = function(owner, name, fullName, builder) {
+ scalaxy.lazy.builders_[fullName] = builder;
+ Object.defineProperty(owner, name, {
+ configurable: true,
+ enumerable: true,
+ get: function() {
+ var value = scalaxy.lazy.get(fullName, builder);
+ Object.defineProperty(owner, name, {
+ enumerable: true,
+ value: value
+ });
+ return value;
+ }
+ });
+};
+
+/**
+ * @param {string} fullName
+ * @param {(function(): Object)=} opt_builder
+ */
+scalaxy.lazy.get = function(fullName, opt_builder) {
+ var value = scalaxy.lazy.values_[fullName];
+ if (!value) {
+ var builder = opt_builder || scalaxy.lazy.builders_[fullName];
+ if (!builder) {
+ throw new Error("No such lazy value: " + fullName);
+ } else {
+ scalaxy.lazy.builders_[fullName] = undefined;
+ }
+ value = builder();
+ if (!value) {
+ throw new Error("Lazy value builders must not evaluate to falsey value.");
+ }
+ scalaxy.lazy.values_[fullName] = value;
+ }
+ return value;
+};
View
0  ...S/src/main/scala/scalaxy/js/package.scala → ...e/src/main/scala/scalaxy/js/package.scala
File renamed without changes
View
11 Experiments/JS/Core/src/main/scala/scalaxy/js/runtime/DynamicValue.scala
@@ -0,0 +1,11 @@
+package scalaxy.js
+
+import scala.language.dynamics
+
+class DynamicValue(value: Any) extends Dynamic {
+ ???
+ def applyDynamic(name: String)(args: Any*): Any = ???
+ def selectDynamic(name: String): Any = ???
+ def updateDynamic(name: String)(value: Any) = ???
+}
+
View
13 Experiments/JS/Core/src/main/scala/scalaxy/js/runtime/Union.scala
@@ -0,0 +1,13 @@
+package scalaxy.js
+
+import scala.language.implicitConversions
+
+class |[A, B](val value: Any)
+object | {
+ implicit def union[A, B](value: Any): (A | B) = new |[A, B](value)
+}
+
+// class Union[A, B](val value: Any)
+// object Union {
+// implicit def union[A, B](value: Any): Union[A, B] = new Union[A, B](value)
+// }
View
28 Experiments/JS/Core/src/test/scala/scalaxy/js/MixinsTest.scala
@@ -0,0 +1,28 @@
+package scalaxy.js
+
+import org.junit._
+import Assert._
+
+class MixinsTest {
+ trait A { def foo = "A" }
+ trait B { def foo = "B" }
+
+ @Test
+ def simple {
+ // class C extends A with B
+ assertEquals("A",
+ (new A {}).foo)
+
+ assertEquals("super = A",
+ (new A { override def foo = "super = " + super.foo }).foo)
+
+ assertEquals("C",
+ (new A with B { override def foo = "C" }).foo)
+
+ assertEquals("super = A",
+ (new A with B { override def foo = "super = " + super[A].foo }).foo)
+
+ assertEquals("super = B",
+ (new A with B { override def foo = "super = " + super[B].foo }).foo)
+ }
+}
View
39 Experiments/JS/Generator/src/main/javascript/experiments.js
@@ -0,0 +1,39 @@
+goog.require("scalaxy.lang.Class");
+goog.require("scalaxy.lang.Object");
+
+
+/*
+package test
+class Test(val x: Int) [extends AnyRef] {
+ def blah = println("blah " + x)
+
+ println("Constructing Test with x = " + x)
+}
+*/
+
+if (!test) var test = {};
+
+/**
+ * @constructor
+ * @extends {scalaxy.lang.Object}
+ * @param {number} x
+ */
+test.Test = function(x) {
+ goog.base(this);
+ this.x = x;
+ window.console.log('Constructing Test with x = ' + this.x)
+};
+goog.inherits(test.Test, scalaxy.lang.Object);
+
+scalaxy.lang.Class.defineClass({
+ name: "test.Test",
+ constructor: test.Test,
+ base: scalaxy.lang.Object
+});
+