Adding mapbox-gl branch
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// Copyright 2012 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 A labs location for functions destined for Closure's
|
||||
* {@code goog.object} namespace.
|
||||
* @author chrishenry@google.com (Chris Henry)
|
||||
*/
|
||||
|
||||
goog.provide('goog.labs.object');
|
||||
|
||||
|
||||
/**
|
||||
* Whether two values are not observably distinguishable. This
|
||||
* correctly detects that 0 is not the same as -0 and two NaNs are
|
||||
* practically equivalent.
|
||||
*
|
||||
* The implementation is as suggested by harmony:egal proposal.
|
||||
*
|
||||
* @param {*} v The first value to compare.
|
||||
* @param {*} v2 The second value to compare.
|
||||
* @return {boolean} Whether two values are not observably distinguishable.
|
||||
* @see http://wiki.ecmascript.org/doku.php?id=harmony:egal
|
||||
*/
|
||||
goog.labs.object.is = function(v, v2) {
|
||||
if (v === v2) {
|
||||
// 0 === -0, but they are not identical.
|
||||
// We need the cast because the compiler requires that v2 is a
|
||||
// number (although 1/v2 works with non-number). We cast to ? to
|
||||
// stop the compiler from type-checking this statement.
|
||||
return v !== 0 || 1 / v === 1 / /** @type {?} */ (v2);
|
||||
}
|
||||
|
||||
// NaN is non-reflexive: NaN !== NaN, although they are identical.
|
||||
return v !== v && v2 !== v2;
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2012 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
-->
|
||||
<!--
|
||||
Author: chrishenry@google.com (Chris Henry)
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<title>
|
||||
Closure Unit Tests - goog.labs.object
|
||||
</title>
|
||||
<script src="../../base.js">
|
||||
</script>
|
||||
<script>
|
||||
goog.require('goog.labs.objectTest');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2012 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.
|
||||
|
||||
goog.provide('goog.labs.objectTest');
|
||||
goog.setTestOnly('goog.labs.objectTest');
|
||||
|
||||
goog.require('goog.labs.object');
|
||||
goog.require('goog.testing.jsunit');
|
||||
|
||||
function testIs() {
|
||||
var object = {};
|
||||
assertTrue(goog.labs.object.is(object, object));
|
||||
assertFalse(goog.labs.object.is(object, {}));
|
||||
|
||||
assertTrue(goog.labs.object.is(NaN, NaN));
|
||||
assertTrue(goog.labs.object.is(0, 0));
|
||||
assertTrue(goog.labs.object.is(1, 1));
|
||||
assertTrue(goog.labs.object.is(-1, -1));
|
||||
assertTrue(goog.labs.object.is(123, 123));
|
||||
assertFalse(goog.labs.object.is(0, -0));
|
||||
assertFalse(goog.labs.object.is(-0, 0));
|
||||
assertFalse(goog.labs.object.is(0, 1));
|
||||
|
||||
assertTrue(goog.labs.object.is(true, true));
|
||||
assertTrue(goog.labs.object.is(false, false));
|
||||
assertFalse(goog.labs.object.is(true, false));
|
||||
assertFalse(goog.labs.object.is(false, true));
|
||||
|
||||
assertTrue(goog.labs.object.is('', ''));
|
||||
assertTrue(goog.labs.object.is('a', 'a'));
|
||||
assertFalse(goog.labs.object.is('', 'a'));
|
||||
assertFalse(goog.labs.object.is('a', ''));
|
||||
assertFalse(goog.labs.object.is('a', 'b'));
|
||||
|
||||
assertFalse(goog.labs.object.is(true, 'true'));
|
||||
assertFalse(goog.labs.object.is('true', true));
|
||||
assertFalse(goog.labs.object.is(false, 'false'));
|
||||
assertFalse(goog.labs.object.is('false', false));
|
||||
assertFalse(goog.labs.object.is(0, '0'));
|
||||
assertFalse(goog.labs.object.is('0', 0));
|
||||
}
|
||||
Reference in New Issue
Block a user