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

Commit ba796b9

Browse files
authored
Merge pull request #155 from wilddamon/imagevalue-constructor
Make style used for hiding CSSImageValue's constructor consistent with other code
2 parents 48bed39 + c86ca1e commit ba796b9

File tree

4 files changed

+46
-46
lines changed

4 files changed

+46
-46
lines changed

src/css-image-value.js

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

1515
(function(internal, scope) {
1616

17-
(function() {
18-
function CSSImageValue() {
19-
throw new TypeError("Can\'t instantiate CSSImageValue");
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;
2023
}
21-
internal.inherit(CSSImageValue, CSSResourceValue);
24+
}
2225

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

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

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-
}
34+
var CSSImageValue = function() {
35+
throw new TypeError('CSSImageValue cannot be instantiated');
36+
}
37+
internal.inherit(CSSImageValue, CSSResourceValue);
3838

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

43-
function onProgress() {
44-
this.state = "loading";
41+
(function() {
42+
function CSSImageValue(image) {
43+
if (!(image instanceof Image)) {
44+
throw new TypeError("image must be an Image object");
45+
}
46+
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);
4555
}
56+
CSSImageValue.prototype = Object.create(scope.CSSImageValue.prototype);
4657

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;
58+
internal.CSSImageValue = CSSImageValue;
59+
})();
6060

6161
})(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: 4 additions & 5 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() {
@@ -25,7 +24,7 @@ suite('CSSImageValue', function() {
2524
assert.instanceOf(new typedOM.internal.CSSImageValue(new Image()), CSSStyleValue);
2625
});
2726

28-
test('CSSImageValue only accepts Image object', function() {
27+
test('CSSImageValue only accepts Image objects', function() {
2928
var imageErr = /image must be an Image object/;
3029
assert.throws(function() { new typedOM.internal.CSSImageValue(); }, TypeError, imageErr);
3130
assert.throws(function() { new typedOM.internal.CSSImageValue(1); }, TypeError, imageErr);
@@ -34,7 +33,7 @@ suite('CSSImageValue', function() {
3433
assert.throws(function() { new typedOM.internal.CSSImageValue({ x: 1, y: 2 }); }, TypeError, imageErr);
3534
});
3635

37-
test('CSSImageValue\'s state and dimensions are correct before and after loaded', function(done) {
36+
test('State and dimensions are correct before and after loading', function(done) {
3837
var image = new typedOM.internal.CSSImageValue(new Image());
3938
assert.strictEqual(image.state, "unloaded");
4039
assert.strictEqual(image.intrinsicWidth, null);

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)