Added js and js_util to observatory deps
R=johnmccutchan@google.com
Review URL: https://codereview.chromium.org//2104113003 .
diff --git a/packages/js/js.dart b/packages/js/js.dart
new file mode 100644
index 0000000..17b1ded
--- /dev/null
+++ b/packages/js/js.dart
@@ -0,0 +1,32 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Allows interoperability with Javascript APIs.
+library js;
+
+export 'dart:js' show allowInterop, allowInteropCaptureThis;
+
+/// A metadata annotation that indicates that a Library, Class, or member is
+/// implemented directly in JavaScript. All external members of a class or
+/// library with this annotation implicitly have it as well.
+///
+/// Specifying [name] customizes the JavaScript name to use. By default the
+/// dart name is used. It is not valid to specify a custom [name] for class
+/// instance members.
+class JS {
+ final String name;
+ const JS([this.name]);
+}
+
+class _Anonymous {
+ const _Anonymous();
+}
+
+/// A metadata annotation that indicates that a @JS annotated class is
+/// structural and does not have a known JavaScript prototype.
+///
+/// Factory constructors for anonymous JavaScript classes desugar to creating
+/// JavaScript object literals with name-value pairs corresponding to the
+/// parameter names and values.
+const _Anonymous anonymous = const _Anonymous();
diff --git a/packages/js/src/varargs.dart b/packages/js/src/varargs.dart
new file mode 100644
index 0000000..6d316b3
--- /dev/null
+++ b/packages/js/src/varargs.dart
@@ -0,0 +1,64 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Declarations for variable arguments support
+/// (rest params and spread operator).
+///
+/// These are currently *not* supported by dart2js or Dartium.
+library js.varargs;
+
+class _Rest {
+ const _Rest();
+}
+
+/// Annotation to tag ES6 rest parameters (https://goo.gl/r0bJ1K).
+///
+/// This is *not* supported by dart2js or Dartium (yet).
+///
+/// This is meant to be used by the Dart Dev Compiler
+/// when compiling helper functions of its runtime to ES6.
+///
+/// The following function:
+///
+/// foo(a, b, @rest others) { ... }
+///
+/// Will be compiled to ES6 code like the following:
+///
+/// function foo(a, b, ...others) { ... }
+///
+/// Which is roughly equivalent to the following ES5 code:
+///
+/// function foo(a, b/*, ...others*/) {
+/// var others = [].splice.call(arguments, 2);
+/// ...
+/// }
+///
+const _Rest rest = const _Rest();
+
+/// Intrinsic function that maps to the ES6 spread operator
+/// (https://goo.gl/NedHKr).
+///
+/// This is *not* supported by dart2js or Dartium (yet),
+/// and *cannot* be called at runtime.
+///
+/// This is meant to be used by the Dart Dev Compiler when
+/// compiling its runtime to ES6.
+///
+/// The following expression:
+///
+/// foo(a, b, spread(others))
+///
+/// Will be compiled to ES6 code like the following:
+///
+/// foo(a, b, ...others)
+///
+/// Which is roughly equivalent to the following ES5 code:
+///
+/// foo.apply(null, [a, b].concat(others))
+///
+dynamic spread(args) {
+ throw new StateError(
+ 'The spread function cannot be called, '
+ 'it should be compiled away.');
+}
diff --git a/packages/js_util/dist/js_util.js b/packages/js_util/dist/js_util.js
new file mode 100644
index 0000000..b839dd1
--- /dev/null
+++ b/packages/js_util/dist/js_util.js
@@ -0,0 +1,23 @@
+(function (mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ module.exports = mod();
+ else if (typeof define == "function" && define.amd) // AMD
+ return define([], mod);
+ else // Plain browser env
+ this.JsUtil = mod();
+})(function () {
+ "use strict";
+
+ function JsUtil() {
+ }
+
+ JsUtil.newObject = function () {
+ return {};
+ };
+
+ JsUtil.getValue = function (obj, prop) {
+ return obj[prop];
+ };
+
+ return JsUtil;
+});
\ No newline at end of file
diff --git a/packages/js_util/dist/js_util.min.js b/packages/js_util/dist/js_util.min.js
new file mode 100644
index 0000000..c53607e
--- /dev/null
+++ b/packages/js_util/dist/js_util.min.js
@@ -0,0 +1 @@
+(function(mod){if(typeof exports=="object"&&typeof module=="object")module.exports=mod();else if(typeof define=="function"&&define.amd)return define([],mod);else this.JsUtil=mod()})(function(){"use strict";function JsUtil(){}JsUtil.newObject=function(){return{}};JsUtil.getValue=function(obj,prop){return obj[prop]};return JsUtil});
diff --git a/packages/js_util/js_util.dart b/packages/js_util/js_util.dart
new file mode 100644
index 0000000..b0899dc
--- /dev/null
+++ b/packages/js_util/js_util.dart
@@ -0,0 +1,3 @@
+library js_util;
+
+export 'src/js_util_base.dart';
diff --git a/packages/js_util/src/js_util_base.dart b/packages/js_util/src/js_util_base.dart
new file mode 100644
index 0000000..7f35991
--- /dev/null
+++ b/packages/js_util/src/js_util_base.dart
@@ -0,0 +1,59 @@
+@JS()
+library js_util.base;
+
+import 'package:js/js.dart';
+import 'package:quiver_iterables/iterables.dart';
+
+// js_util library uses the technique described in
+// https://github.com/dart-lang/sdk/issues/25053
+// because dart2js compiler does not support [] operator.
+
+@JS()
+@anonymous
+class PropertyDescription {
+ external factory PropertyDescription(
+ {bool configurable, bool enumerable, value, bool writable});
+}
+
+/// A wrapper for https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
+@JS('Object.defineProperty')
+external void defineProperty(o, String prop, PropertyDescription description);
+
+/// Returns `o[prop]`.
+@JS('JsUtil.getValue')
+external getValue(o, String prop);
+
+/// Creates a new JavaScript object.
+@JS('JsUtil.newObject')
+external newObject();
+
+/// Performs `o[key] = value`.
+void setValue(o, String key, value) {
+ defineProperty(o, key, new PropertyDescription(value: value));
+}
+
+/// Converts a Dart object to a JavaScript object.
+///
+/// For example, you can convert a Dart [Map] to a JavaScript object.
+///
+/// final jsObj = toJS({
+/// 'people': [
+/// {'firstName': 'Kwang Yul', 'lastName': 'Seo'},
+/// {'firstName': 'DoHyung', 'lastName': 'Kim'},
+/// {'firstName': 'Kyusun', 'lastName': 'Kim'}
+/// ]
+/// });
+///
+toJS(o) {
+ if (o is Map) {
+ final newObj = newObject();
+ for (final keyValuePair in zip([o.keys, o.values])) {
+ setValue(newObj, keyValuePair[0], toJS(keyValuePair[1]));
+ }
+ return newObj;
+ } else if (o is List) {
+ return o.map((e) => toJS(e)).toList();
+ } else {
+ return o;
+ }
+}
diff --git a/pubspec.yaml b/pubspec.yaml
index e964459..f40c309 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -17,6 +17,8 @@
charted: ^0.3.0
polymer: ^0.16.3
unittest: < 0.12.0
+ js: ^0.6.0
+ js_util: ^0.2.0
usage: any
dependency_overrides:
analyzer: '>=0.26.1 <0.26.1+15'