Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Unified Diff: lib/runtime/dart/_utils.js

Issue 1486473002: Convert dart_utils.js to input_sdk/lib/_internal/utils.dart (#310) (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Rebased Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/runtime/dart/_types.js ('k') | lib/runtime/dart_library.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/runtime/dart/_utils.js
diff --git a/lib/runtime/dart_utils.js b/lib/runtime/dart/_utils.js
similarity index 50%
rename from lib/runtime/dart_utils.js
rename to lib/runtime/dart/_utils.js
index a7490b9df544087634dcb8f9b30486aa2a19098a..5dee5707711013639c4a3883cdd68d16af19fe1a 100644
--- a/lib/runtime/dart_utils.js
+++ b/lib/runtime/dart/_utils.js
@@ -1,70 +1,42 @@
-// 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.
-
-/* This library defines a set of general javascript utilities for us
- * by the Dart runtime.
-*/
-
-var dart_utils =
- typeof module != "undefined" && module.exports || {};
-
-(function (dart_utils) {
+dart_library.library('dart/_utils', null, /* Imports */[
+], /* Lazy imports */[
+], function(exports, dart) {
'use strict';
-
const defineProperty = Object.defineProperty;
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
const getOwnPropertyNames = Object.getOwnPropertyNames;
const getOwnPropertySymbols = Object.getOwnPropertySymbols;
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
-
- class StrongModeError extends Error {
- constructor(message) {
- super(message);
+ const StrongModeError = (function() {
+ function StrongModeError(message) {
+ Error.call(this);
+ this.message = message;
}
- }
-
- /** This error indicates a strong mode specific failure.
- */
+ ;
+ Object.setPrototypeOf(StrongModeError.prototype, Error.prototype);
+ return StrongModeError;
+ })();
function throwStrongModeError(message) {
throw new StrongModeError(message);
}
- dart_utils.throwStrongModeError = throwStrongModeError;
-
- /** This error indicates a bug in the runtime or the compiler.
- */
function throwInternalError(message) {
throw Error(message);
}
- dart_utils.throwInternalError = throwInternalError;
-
- function assert(condition) {
- if (!condition) throwInternalError("The compiler is broken: failed assert");
+ function assert_(condition) {
+ if (!condition)
+ throwInternalError("The compiler is broken: failed assert");
}
- dart_utils.assert = assert;
-
function getOwnNamesAndSymbols(obj) {
return getOwnPropertyNames(obj).concat(getOwnPropertySymbols(obj));
}
- dart_utils.getOwnNamesAndSymbols = getOwnNamesAndSymbols;
-
function safeGetOwnProperty(obj, name) {
let desc = getOwnPropertyDescriptor(obj, name);
- if (desc) return desc.value;
+ if (desc)
+ return desc.value;
}
- dart_utils.safeGetOwnProperty = safeGetOwnProperty;
-
- /**
- * Defines a lazy property.
- * After initial get or set, it will replace itself with a value property.
- */
- // TODO(jmesserly): reusing descriptor objects has been shown to improve
- // performance in other projects (e.g. webcomponents.js ShadowDOM polyfill).
function defineLazyProperty(to, name, desc) {
let init = desc.get;
let value = null;
-
function lazySetter(x) {
init = null;
value = x;
@@ -73,9 +45,8 @@ var dart_utils =
throwInternalError('circular initialization for field ' + name);
}
function lazyGetter() {
- if (init == null) return value;
-
- // Compute and store the value, guarding against reentry.
+ if (init == null)
+ return value;
let f = init;
init = circularInitError;
lazySetter(f());
@@ -83,51 +54,53 @@ var dart_utils =
}
desc.get = lazyGetter;
desc.configurable = true;
- if (desc.set) desc.set = lazySetter;
+ if (desc.set)
+ desc.set = lazySetter;
return defineProperty(to, name, desc);
}
- dart_utils.defineLazyProperty = defineLazyProperty;
-
function defineLazy(to, from) {
for (let name of getOwnNamesAndSymbols(from)) {
defineLazyProperty(to, name, getOwnPropertyDescriptor(from, name));
}
}
- dart_utils.defineLazy = defineLazy;
-
function defineMemoizedGetter(obj, name, getter) {
return defineLazyProperty(obj, name, {get: getter});
}
- dart_utils.defineMemoizedGetter = defineMemoizedGetter;
-
function copyTheseProperties(to, from, names) {
for (let name of names) {
defineProperty(to, name, getOwnPropertyDescriptor(from, name));
}
return to;
}
- dart_utils.copyTheseProperties = copyTheseProperties;
-
- /**
- * Copy properties from source to destination object.
- * This operation is commonly called `mixin` in JS.
- */
function copyProperties(to, from) {
return copyTheseProperties(to, from, getOwnNamesAndSymbols(from));
}
- dart_utils.copyProperties = copyProperties;
-
- /** Exports from one Dart module to another. */
function export_(to, from, show, hide) {
if (show == void 0) {
show = getOwnNamesAndSymbols(from);
}
if (hide != void 0) {
var hideMap = new Set(hide);
- show = show.filter((k) => !hideMap.has(k));
+ show = show.filter(k => !hideMap.has(k));
}
return copyTheseProperties(to, from, show);
}
- dart_utils.export = export_;
-
-})(dart_utils);
+ // Exports:
+ exports.defineProperty = defineProperty;
+ exports.getOwnPropertyDescriptor = getOwnPropertyDescriptor;
+ exports.getOwnPropertyNames = getOwnPropertyNames;
+ exports.getOwnPropertySymbols = getOwnPropertySymbols;
+ exports.hasOwnProperty = hasOwnProperty;
+ exports.StrongModeError = StrongModeError;
+ exports.throwStrongModeError = throwStrongModeError;
+ exports.throwInternalError = throwInternalError;
+ exports.assert_ = assert_;
+ exports.getOwnNamesAndSymbols = getOwnNamesAndSymbols;
+ exports.safeGetOwnProperty = safeGetOwnProperty;
+ exports.defineLazyProperty = defineLazyProperty;
+ exports.defineLazy = defineLazy;
+ exports.defineMemoizedGetter = defineMemoizedGetter;
+ exports.copyTheseProperties = copyTheseProperties;
+ exports.copyProperties = copyProperties;
+ exports.export_ = export_;
+});
« no previous file with comments | « lib/runtime/dart/_types.js ('k') | lib/runtime/dart_library.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698