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

Commit ffef302

Browse files
committed
Hide ImageValue base constructor
1 parent 48bed39 commit ffef302

File tree

4 files changed

+44
-45
lines changed

4 files changed

+44
-45
lines changed

src/css-image-value.js

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,47 @@
1414

1515
(function(internal, scope) {
1616

17-
(function() {
18-
function CSSImageValue() {
19-
throw new TypeError("Can\'t instantiate CSSImageValue");
20-
}
21-
internal.inherit(CSSImageValue, CSSResourceValue);
17+
function onLoad() {
18+
this.state = "loaded";
19+
this.intrinsicWidth = this._image.naturalWidth;
20+
this.intrinsicHeight = this._image.naturalHeight;
21+
if (this.intrinsicHeight != 0)
22+
this.intrinsicRatio = this.intrinsicWidth / this.intrinsicHeight;
23+
}
2224

23-
scope.CSSImageValue = CSSImageValue;
24-
})();
25+
function onError() {
26+
this.state = "error";
27+
}
2528

26-
var CSSImageValue = function(image) {
27-
if (!(image instanceof Image)) {
28-
throw new TypeError("image must be an Image object");
29-
}
29+
function onProgress() {
30+
this.state = "loading";
31+
}
3032

31-
function onLoad() {
32-
this.state = "loaded";
33-
this.intrinsicWidth = this._image.naturalWidth;
34-
this.intrinsicHeight = this._image.naturalHeight;
35-
if (this.intrinsicHeight != 0)
36-
this.intrinsicRatio = this.intrinsicWidth / this.intrinsicHeight;
37-
}
33+
var CSSImageValue = function() {
34+
throw new TypeError('CSSImageValue cannot be instantiated');
35+
}
36+
internal.inherit(CSSImageValue, CSSResourceValue);
3837

39-
function onError() {
40-
this.state = "error";
41-
}
38+
scope.CSSImageValue = CSSImageValue;
4239

43-
function onProgress() {
44-
this.state = "loading";
40+
(function() {
41+
function CSSImageValue(image) {
42+
if (!(image instanceof Image)) {
43+
throw new TypeError("image must be an Image object");
44+
}
45+
46+
this._image = image;
47+
this.state = "unloaded";
48+
this.intrinsicWidth = null;
49+
this.intrinsicHeight = null;
50+
this.intrinsicRatio = null;
51+
this._image.onload = onLoad.bind(this);
52+
this._image.onerror = onError.bind(this);
53+
this._image.onprogess = onProgress.bind(this);
4554
}
55+
CSSImageValue.prototype = Object.create(scope.CSSImageValue.prototype);
4656

47-
this._image = image;
48-
this.state = "unloaded";
49-
this.intrinsicWidth = null;
50-
this.intrinsicHeight = null;
51-
this.intrinsicRatio = null;
52-
this._image.onload = onLoad.bind(this);
53-
this._image.onerror = onError.bind(this);
54-
this._image.onprogess = onProgress.bind(this);
55-
}
56-
57-
CSSImageValue.prototype = Object.create(scope.CSSImageValue.prototype);
58-
59-
internal.CSSImageValue = CSSImageValue;
57+
internal.CSSImageValue = CSSImageValue;
58+
})();
6059

6160
})(typedOM.internal, window);

src/css-url-image-value.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
throw new TypeError("URL must be a string");
2020
}
2121
internal.CSSImageValue.call(this, new Image());
22+
2223
this._image.src = url;
2324
this.url = url;
2425
this.cssText = 'url(' + this.url + ')';
2526
}
26-
27-
internal.inherit(CSSURLImageValue, internal.CSSImageValue);
27+
internal.inherit(CSSURLImageValue, CSSImageValue);
2828

2929
scope.CSSURLImageValue = CSSURLImageValue;
3030

test/js/css-image-value.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
// limitations under the License.
1414

1515
suite('CSSImageValue', function() {
16-
test('Can only create internal CSSImageValue object', function() {
17-
var instantiateErr = /^Can't instantiate CSSImageValue$/;
16+
test('Cannot instantiate base CSSImageValue', function() {
17+
var instantiateErr = /^CSSImageValue cannot be instantiated$/;
1818
assert.throws(function() { new CSSImageValue(new Image()); }, TypeError, instantiateErr);
19-
assert.doesNotThrow(function() { new typedOM.internal.CSSImageValue(new Image()); });
2019
});
2120

2221
test('CSSImageValue object is a CSSImageValue, CSSResourceValue, and CSSStyleValue', function() {

test/js/css-url-image-value.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
suite('CSSURLImageValue', function() {
1616
test('CSSURLImageValue is a CSSURLImageValue, CSSImageValue, CSSResourceValue, and CSSStyleValue', function() {
17-
assert.instanceOf(new CSSURLImageValue('resources/1x1-green.png'), CSSURLImageValue);
18-
assert.instanceOf(new CSSURLImageValue('resources/1x1-green.png'), CSSImageValue);
19-
assert.instanceOf(new CSSURLImageValue('resources/1x1-green.png'), CSSResourceValue);
20-
assert.instanceOf(new CSSURLImageValue('resources/1x1-green.png'), CSSStyleValue);
17+
var imageValue = new CSSURLImageValue('resources/1x1-green.png');
18+
assert.instanceOf(imageValue, CSSURLImageValue);
19+
assert.instanceOf(imageValue, CSSImageValue);
20+
assert.instanceOf(imageValue, CSSResourceValue);
21+
assert.instanceOf(imageValue, CSSStyleValue);
2122
});
2223

2324
test('CSSURLImageValue only accepts string', function() {

0 commit comments

Comments
 (0)