@@ -1828,24 +1828,26 @@ NAN_GETTER(Context2d::GetFillStyle) {
1828
1828
NAN_SETTER (Context2d::SetFillStyle) {
1829
1829
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This ());
1830
1830
1831
- if (Nan::New (Gradient::constructor)->HasInstance (value) ||
1832
- Nan::New (Pattern::constructor)->HasInstance (value)) {
1833
- context->_fillStyle .Reset (value);
1834
-
1831
+ if (value->IsString ()) {
1832
+ MaybeLocal<String> mstr = Nan::To<String>(value);
1833
+ if (mstr.IsEmpty ()) return ;
1834
+ Local<String> str = mstr.ToLocalChecked ();
1835
+ context->_fillStyle .Reset ();
1836
+ context->_setFillColor (str);
1837
+ } else if (value->IsObject ()) {
1835
1838
Local<Object> obj = Nan::To<Object>(value).ToLocalChecked ();
1836
- if (Nan::New (Gradient::constructor)->HasInstance (obj)){
1839
+ if (Nan::New (Gradient::constructor)->HasInstance (obj)) {
1840
+ context->_fillStyle .Reset (value);
1837
1841
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(obj);
1838
1842
context->state ->fillGradient = grad->pattern ();
1839
- } else if (Nan::New (Pattern::constructor)->HasInstance (obj)){
1843
+ } else if (Nan::New (Pattern::constructor)->HasInstance (obj)) {
1844
+ context->_fillStyle .Reset (value);
1840
1845
Pattern *pattern = Nan::ObjectWrap::Unwrap<Pattern>(obj);
1841
1846
context->state ->fillPattern = pattern->pattern ();
1847
+ } else {
1848
+ // TODO this is non-standard
1849
+ Nan::ThrowTypeError (" Gradient or Pattern expected" );
1842
1850
}
1843
- } else {
1844
- MaybeLocal<String> mstr = Nan::To<String>(value);
1845
- if (mstr.IsEmpty ()) return ;
1846
- Local<String> str = mstr.ToLocalChecked ();
1847
- context->_fillStyle .Reset ();
1848
- context->_setFillColor (str);
1849
1851
}
1850
1852
}
1851
1853
@@ -1872,26 +1874,26 @@ NAN_GETTER(Context2d::GetStrokeStyle) {
1872
1874
NAN_SETTER (Context2d::SetStrokeStyle) {
1873
1875
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This ());
1874
1876
1875
- if (Nan::New (Gradient::constructor)->HasInstance (value) ||
1876
- Nan::New (Pattern::constructor)->HasInstance (value)) {
1877
- context->_strokeStyle .Reset (value);
1878
-
1877
+ if (value->IsString ()) {
1878
+ MaybeLocal<String> mstr = Nan::To<String>(value);
1879
+ if (mstr.IsEmpty ()) return ;
1880
+ Local<String> str = mstr.ToLocalChecked ();
1881
+ context->_strokeStyle .Reset ();
1882
+ context->_setStrokeColor (str);
1883
+ } else if (value->IsObject ()) {
1879
1884
Local<Object> obj = Nan::To<Object>(value).ToLocalChecked ();
1880
- if (Nan::New (Gradient::constructor)->HasInstance (obj)){
1885
+ if (Nan::New (Gradient::constructor)->HasInstance (obj)) {
1886
+ context->_strokeStyle .Reset (value);
1881
1887
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(obj);
1882
1888
context->state ->strokeGradient = grad->pattern ();
1883
- } else if (Nan::New (Pattern::constructor)->HasInstance (obj)){
1889
+ } else if (Nan::New (Pattern::constructor)->HasInstance (obj)) {
1890
+ context->_strokeStyle .Reset (value);
1884
1891
Pattern *pattern = Nan::ObjectWrap::Unwrap<Pattern>(obj);
1885
1892
context->state ->strokePattern = pattern->pattern ();
1886
1893
} else {
1894
+ // TODO this is non-standard
1887
1895
return Nan::ThrowTypeError (" Gradient or Pattern expected" );
1888
1896
}
1889
- } else {
1890
- MaybeLocal<String> mstr = Nan::To<String>(value);
1891
- if (mstr.IsEmpty ()) return ;
1892
- Local<String> str = mstr.ToLocalChecked ();
1893
- context->_strokeStyle .Reset ();
1894
- context->_setStrokeColor (str);
1895
1897
}
1896
1898
}
1897
1899
0 commit comments