Skip to content

Commit b10d204

Browse files
Hakerh400zbjornson
authored andcommitted
Remove deprecation warning for v8::String::Utf8Value (#1191)
* Fix deprecation warning related to String::Utf8Value * Fix failing test * Suppress alignment warning * Switch to Nan::Utf8String to make it compatible with v6.x * Fix test
1 parent 8ecfbaa commit b10d204

File tree

6 files changed

+36
-33
lines changed

6 files changed

+36
-33
lines changed

src/Canvas.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ NAN_METHOD(Canvas::New) {
9393
if (info[1]->IsNumber()) height = info[1]->Uint32Value();
9494

9595
if (info[2]->IsString()) {
96-
if (0 == strcmp("pdf", *String::Utf8Value(info[2])))
96+
if (0 == strcmp("pdf", *Nan::Utf8String(info[2])))
9797
backend = new PdfBackend(width, height);
98-
else if (0 == strcmp("svg", *String::Utf8Value(info[2])))
98+
else if (0 == strcmp("svg", *Nan::Utf8String(info[2])))
9999
backend = new SvgBackend(width, height);
100100
else
101101
backend = new ImageBackend(width, height);
@@ -638,7 +638,7 @@ NAN_METHOD(Canvas::StreamJPEGSync) {
638638
char *
639639
str_value(Local<Value> val, const char *fallback, bool can_be_number) {
640640
if (val->IsString() || (can_be_number && val->IsNumber())) {
641-
return g_strdup(*String::Utf8Value(val));
641+
return g_strdup(*Nan::Utf8String(val));
642642
} else if (fallback) {
643643
return g_strdup(fallback);
644644
} else {
@@ -653,7 +653,7 @@ NAN_METHOD(Canvas::RegisterFont) {
653653
return Nan::ThrowError(GENERIC_FACE_ERROR);
654654
}
655655

656-
String::Utf8Value filePath(info[0]);
656+
Nan::Utf8String filePath(info[0]);
657657
PangoFontDescription *sys_desc = get_pango_font_description((unsigned char *) *filePath);
658658

659659
if (!sys_desc) return Nan::ThrowError("Could not parse font file");

src/CanvasGradient.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ NAN_METHOD(Gradient::AddColorStop) {
8080

8181
Gradient *grad = Nan::ObjectWrap::Unwrap<Gradient>(info.This());
8282
short ok;
83-
String::Utf8Value str(info[1]);
83+
Nan::Utf8String str(info[1]);
8484
uint32_t rgba = rgba_from_string(*str, &ok);
8585

8686
if (ok) {

src/CanvasPattern.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ NAN_METHOD(Pattern::New) {
6464
return Nan::ThrowTypeError("Image or Canvas expected");
6565
}
6666
repeat_type_t repeat = REPEAT;
67-
if (0 == strcmp("no-repeat", *String::Utf8Value(info[1]))) {
67+
if (0 == strcmp("no-repeat", *Nan::Utf8String(info[1]))) {
6868
repeat = NO_REPEAT;
69-
} else if (0 == strcmp("repeat-x", *String::Utf8Value(info[1]))) {
69+
} else if (0 == strcmp("repeat-x", *Nan::Utf8String(info[1]))) {
7070
repeat = REPEAT_X;
71-
} else if (0 == strcmp("repeat-y", *String::Utf8Value(info[1]))) {
71+
} else if (0 == strcmp("repeat-y", *Nan::Utf8String(info[1]))) {
7272
repeat = REPEAT_Y;
7373
}
7474
Pattern *pattern = new Pattern(surface, repeat);

src/CanvasRenderingContext2d.cc

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void
335335
Context2d::setFillRule(v8::Local<v8::Value> value) {
336336
cairo_fill_rule_t rule = CAIRO_FILL_RULE_WINDING;
337337
if (value->IsString()) {
338-
String::Utf8Value str(value);
338+
Nan::Utf8String str(value);
339339
if (std::strcmp(*str, "evenodd") == 0) {
340340
rule = CAIRO_FILL_RULE_EVEN_ODD;
341341
}
@@ -654,7 +654,7 @@ NAN_METHOD(Context2d::New) {
654654

655655
Local<Value> pixelFormat = ctxAttributes->Get(Nan::New("pixelFormat").ToLocalChecked());
656656
if (pixelFormat->IsString()) {
657-
String::Utf8Value utf8PixelFormat(pixelFormat);
657+
Nan::Utf8String utf8PixelFormat(pixelFormat);
658658
if (!strcmp(*utf8PixelFormat, "RGBA32")) format = CAIRO_FORMAT_ARGB32;
659659
else if (!strcmp(*utf8PixelFormat, "RGB24")) format = CAIRO_FORMAT_RGB24;
660660
else if (!strcmp(*utf8PixelFormat, "A8")) format = CAIRO_FORMAT_A8;
@@ -1335,7 +1335,7 @@ NAN_GETTER(Context2d::GetGlobalCompositeOperation) {
13351335

13361336
NAN_SETTER(Context2d::SetPatternQuality) {
13371337
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
1338-
String::Utf8Value quality(value->ToString());
1338+
Nan::Utf8String quality(value->ToString());
13391339
if (0 == strcmp("fast", *quality)) {
13401340
context->state->patternQuality = CAIRO_FILTER_FAST;
13411341
} else if (0 == strcmp("good", *quality)) {
@@ -1373,7 +1373,7 @@ NAN_GETTER(Context2d::GetPatternQuality) {
13731373
NAN_SETTER(Context2d::SetGlobalCompositeOperation) {
13741374
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
13751375
cairo_t *ctx = context->context();
1376-
String::Utf8Value type(value->ToString());
1376+
Nan::Utf8String type(value->ToString());
13771377
if (0 == strcmp("xor", *type)) {
13781378
cairo_set_operator(ctx, CAIRO_OPERATOR_XOR);
13791379
} else if (0 == strcmp("source-atop", *type)) {
@@ -1521,7 +1521,7 @@ NAN_GETTER(Context2d::GetAntiAlias) {
15211521
*/
15221522

15231523
NAN_SETTER(Context2d::SetAntiAlias) {
1524-
String::Utf8Value str(value->ToString());
1524+
Nan::Utf8String str(value->ToString());
15251525
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
15261526
cairo_t *ctx = context->context();
15271527
cairo_antialias_t a;
@@ -1561,7 +1561,7 @@ NAN_GETTER(Context2d::GetTextDrawingMode) {
15611561
*/
15621562

15631563
NAN_SETTER(Context2d::SetTextDrawingMode) {
1564-
String::Utf8Value str(value->ToString());
1564+
Nan::Utf8String str(value->ToString());
15651565
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
15661566
if (0 == strcmp("path", *str)) {
15671567
context->state->textDrawingMode = TEXT_DRAW_PATHS;
@@ -1592,7 +1592,7 @@ NAN_GETTER(Context2d::GetFilter) {
15921592
*/
15931593

15941594
NAN_SETTER(Context2d::SetFilter) {
1595-
String::Utf8Value str(value->ToString());
1595+
Nan::Utf8String str(value->ToString());
15961596
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
15971597
cairo_filter_t filter;
15981598
if (0 == strcmp("fast", *str)) {
@@ -1673,7 +1673,7 @@ NAN_GETTER(Context2d::GetLineJoin) {
16731673
NAN_SETTER(Context2d::SetLineJoin) {
16741674
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
16751675
cairo_t *ctx = context->context();
1676-
String::Utf8Value type(value->ToString());
1676+
Nan::Utf8String type(value->ToString());
16771677
if (0 == strcmp("round", *type)) {
16781678
cairo_set_line_join(ctx, CAIRO_LINE_JOIN_ROUND);
16791679
} else if (0 == strcmp("bevel", *type)) {
@@ -1705,7 +1705,7 @@ NAN_GETTER(Context2d::GetLineCap) {
17051705
NAN_SETTER(Context2d::SetLineCap) {
17061706
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
17071707
cairo_t *ctx = context->context();
1708-
String::Utf8Value type(value->ToString());
1708+
Nan::Utf8String type(value->ToString());
17091709
if (0 == strcmp("round", *type)) {
17101710
cairo_set_line_cap(ctx, CAIRO_LINE_CAP_ROUND);
17111711
} else if (0 == strcmp("square", *type)) {
@@ -1780,7 +1780,7 @@ NAN_METHOD(Context2d::SetStrokePattern) {
17801780

17811781
NAN_SETTER(Context2d::SetShadowColor) {
17821782
short ok;
1783-
String::Utf8Value str(value->ToString());
1783+
Nan::Utf8String str(value->ToString());
17841784
uint32_t rgba = rgba_from_string(*str, &ok);
17851785
if (ok) {
17861786
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
@@ -1807,7 +1807,7 @@ NAN_METHOD(Context2d::SetFillColor) {
18071807
short ok;
18081808

18091809
if (!info[0]->IsString()) return;
1810-
String::Utf8Value str(info[0]);
1810+
Nan::Utf8String str(info[0]);
18111811

18121812
uint32_t rgba = rgba_from_string(*str, &ok);
18131813
if (!ok) return;
@@ -1835,7 +1835,7 @@ NAN_METHOD(Context2d::SetStrokeColor) {
18351835
short ok;
18361836

18371837
if (!info[0]->IsString()) return;
1838-
String::Utf8Value str(info[0]);
1838+
Nan::Utf8String str(info[0]);
18391839

18401840
uint32_t rgba = rgba_from_string(*str, &ok);
18411841
if (!ok) return;
@@ -2085,7 +2085,7 @@ NAN_METHOD(Context2d::FillText) {
20852085
if(!checkArgs(info, args, argsNum, 1))
20862086
return;
20872087

2088-
String::Utf8Value str(info[0]->ToString());
2088+
Nan::Utf8String str(info[0]->ToString());
20892089
double x = args[0];
20902090
double y = args[1];
20912091
double scaled_by = 1;
@@ -2120,7 +2120,7 @@ NAN_METHOD(Context2d::StrokeText) {
21202120
if(!checkArgs(info, args, argsNum, 1))
21212121
return;
21222122

2123-
String::Utf8Value str(info[0]->ToString());
2123+
Nan::Utf8String str(info[0]->ToString());
21242124
double x = args[0];
21252125
double y = args[1];
21262126
double scaled_by = 1;
@@ -2245,11 +2245,11 @@ NAN_METHOD(Context2d::SetFont) {
22452245
|| !info[3]->IsString()
22462246
|| !info[4]->IsString()) return;
22472247

2248-
String::Utf8Value weight(info[0]);
2249-
String::Utf8Value style(info[1]);
2248+
Nan::Utf8String weight(info[0]);
2249+
Nan::Utf8String style(info[1]);
22502250
double size = info[2]->NumberValue();
2251-
String::Utf8Value unit(info[3]);
2252-
String::Utf8Value family(info[4]);
2251+
Nan::Utf8String unit(info[3]);
2252+
Nan::Utf8String family(info[4]);
22532253

22542254
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
22552255

@@ -2282,7 +2282,7 @@ NAN_METHOD(Context2d::MeasureText) {
22822282
Context2d *context = Nan::ObjectWrap::Unwrap<Context2d>(info.This());
22832283
cairo_t *ctx = context->context();
22842284

2285-
String::Utf8Value str(info[0]->ToString());
2285+
Nan::Utf8String str(info[0]->ToString());
22862286
Local<Object> obj = Nan::New<Object>();
22872287

22882288
PangoRectangle _ink_rect, _logical_rect;

src/Image.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ typedef struct {
2525
#include <csetjmp>
2626

2727
struct canvas_jpeg_error_mgr: jpeg_error_mgr {
28-
jmp_buf setjmp_buffer;
28+
private: char unused[8];
29+
public: jmp_buf setjmp_buffer;
2930
};
3031
#endif
3132

@@ -229,7 +230,7 @@ NAN_SETTER(Image::SetSource) {
229230

230231
// url string
231232
if (value->IsString()) {
232-
String::Utf8Value src(value);
233+
Nan::Utf8String src(value);
233234
if (img->filename) free(img->filename);
234235
img->filename = strdup(*src);
235236
status = img->load();

test/canvas.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,23 +547,25 @@ describe('Canvas', function () {
547547
});
548548
});
549549

550-
it('Canvas#toBuffer(callback, "image/jpeg")', function () {
551-
var buf = createCanvas(200,200).toBuffer(function (err, buff) {
550+
it('Canvas#toBuffer(callback, "image/jpeg")', function (done) {
551+
createCanvas(200,200).toBuffer(function (err, buf) {
552552
assert.ok(!err);
553553
assert.equal(buf[0], 0xff);
554554
assert.equal(buf[1], 0xd8);
555555
assert.equal(buf[buf.byteLength - 2], 0xff);
556556
assert.equal(buf[buf.byteLength - 1], 0xd9);
557+
done();
557558
}, 'image/jpeg');
558559
});
559560

560-
it('Canvas#toBuffer(callback, "image/jpeg", {quality: 0.95})', function () {
561-
var buf = createCanvas(200,200).toBuffer(function (err, buff) {
561+
it('Canvas#toBuffer(callback, "image/jpeg", {quality: 0.95})', function (done) {
562+
createCanvas(200,200).toBuffer(function (err, buf) {
562563
assert.ok(!err);
563564
assert.equal(buf[0], 0xff);
564565
assert.equal(buf[1], 0xd8);
565566
assert.equal(buf[buf.byteLength - 2], 0xff);
566567
assert.equal(buf[buf.byteLength - 1], 0xd9);
568+
done();
567569
}, 'image/jpeg', {quality: 0.95});
568570
});
569571

0 commit comments

Comments
 (0)