Skip to content
This repository was archived by the owner on Feb 9, 2018. It is now read-only.

Commit e67f65a

Browse files
committed
adds empty CSS.escape polyfill, needed ES6 polyfills
1 parent 86eacfd commit e67f65a

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

src/polyfills.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2016 Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
(function(internal, scope) {
16+
// Adds non-CSS related ES6 polyfills needed for Typed OM.
17+
if (!Number.isFinite) {
18+
Number.isFinite = function(v) { return typeof v === 'number' && isFinite(v); };
19+
}
20+
if (!Number.isInteger) {
21+
Number.isInteger = function(v) {
22+
return typeof v === 'number' && isFinite(v) && Math.floor(v) === v;
23+
};
24+
}
25+
if (!Number.isNaN) {
26+
Number.isNaN = function(v) { return typeof v === 'number' && isNaN(v); };
27+
}
28+
if (!String.prototype.startsWith) {
29+
String.prototype.startsWith = function(v) { return this.substr(0, v.length) === v; };
30+
}
31+
32+
/**
33+
* Escapes the passed string for use as part of a CSS selector. This is a polyfill for browsers
34+
* that do not impement this feature (As of 2016-09, supported only in Chrome and Firefox).
35+
* @param {string|number} str to escape
36+
* @return {string} escaped string
37+
*/
38+
function escape(str) {
39+
// TODO(samthor): Implement escape().
40+
return '' + str;
41+
}
42+
43+
if (!scope.CSS) {
44+
scope.CSS = {};
45+
}
46+
if (!scope.CSS.escape) {
47+
scope.CSS.escape = escape;
48+
}
49+
50+
internal.escape = escape;
51+
})(typedOM.internal, window);

src/style-property-map-readonly.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535

3636
if (internal.propertyDictionary().isSupportedProperty(property)) {
3737
var result = CSSStyleValue.parse(property, propertyString);
38+
if (result == null) {
39+
return null;
40+
}
3841
return Array.isArray(result) ? result : [result];
3942
}
4043
return [new internal.CSSStyleValue(propertyString)];

target-config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
// These should be alphabetical order as much as possible.
2222
var typedOMSrc = [
23+
// Polyfills for missing browser features
24+
'src/polyfills.js',
2325
// Utility functions
2426
'src/util.js',
2527
// CSSTransformComponent and subclasses
@@ -99,6 +101,7 @@
99101
'test/js/css-variable-reference-value.js',
100102
'test/js/computed-style-property-map.js',
101103
'test/js/dom-matrix-readonly.js',
104+
'test/js/escape.js',
102105
'test/js/inline-style-property-map.js',
103106
'test/js/parsing.js',
104107
'test/js/property-dictionary.js',

test/js/escape.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2016 Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
suite('CSS.escape polyfill', function() {
16+
var escape = typedOM.internal.escape;
17+
18+
test('Test simple escapes', function() {
19+
assert.equal('test', escape('test'));
20+
});
21+
});

0 commit comments

Comments
 (0)