Skip to content

Commit

Permalink
Fixed build failure and test case on OSX
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostoy committed Nov 19, 2014
1 parent 1309297 commit cfc2689
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/node_buffer.cc
Expand Up @@ -124,11 +124,17 @@ Local<Object> New(Isolate* isolate, Handle<String> string, enum encoding enc) {
if (string->IsExternalAscii()) {
const String::ExternalAsciiStringResource* ext;
ext = string->GetExternalAsciiStringResource();
tmp_string = String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(ext->data()), String::NewStringType::kNormalString, ext->length());
tmp_string = String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(ext->data()),
String::kNormalString,
ext->length());
} else if (string->IsExternal()) {
const String::ExternalStringResource* ext;
ext = string->GetExternalStringResource();
tmp_string = String::NewFromTwoByte(isolate, ext->data(), String::NewStringType::kNormalString, ext->length());
tmp_string = String::NewFromTwoByte(isolate,
ext->data(),
String::kNormalString,
ext->length());
} else {
tmp_string = string;
}
Expand Down
28 changes: 16 additions & 12 deletions src/string_bytes.cc
Expand Up @@ -304,12 +304,14 @@ size_t StringBytes::Write(Isolate* isolate,
CHECK(val->IsString() == true);
Local<String> str = val.As<String>();
bool is_extern_ascii = is_extern && str->IsExternalAscii();
if (is_extern) {
if (is_extern_ascii) {
str = String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(data), String::NewStringType::kNormalString, len);
} else {
str = String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>(data), String::NewStringType::kNormalString, len);
}
if (is_extern_ascii) {
str = String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(data),
String::kNormalString, len);
} else if (is_extern) {
str = String::NewFromTwoByte(isolate,
reinterpret_cast<const uint16_t*>(data),
String::kNormalString, len);
}
len = len < buflen ? len : buflen;

Expand Down Expand Up @@ -445,12 +447,14 @@ size_t StringBytes::Size(Isolate* isolate,

Local<String> str = val->ToString();
bool is_extern_ascii = is_extern && str->IsExternalAscii();
if (is_extern) {
if (is_extern_ascii) {
str = String::NewFromOneByte(isolate, reinterpret_cast<const uint8_t*>(data), String::NewStringType::kNormalString, data_size);
} else {
str = String::NewFromTwoByte(isolate, reinterpret_cast<const uint16_t*>(data), String::NewStringType::kNormalString, data_size);
}
if (is_extern_ascii) {
str = String::NewFromOneByte(isolate,
reinterpret_cast<const uint8_t*>(data),
String::kNormalString, data_size);
} else if (is_extern) {
str = String::NewFromTwoByte(isolate,
reinterpret_cast<const uint16_t*>(data),
String::kNormalString, data_size);
}

switch (encoding) {
Expand Down
5 changes: 5 additions & 0 deletions test/common.js
Expand Up @@ -105,6 +105,11 @@ if (global.gc) {
knownGlobals.push(gc);
}

if (global.externalizeString) {
knownGlobals.push(externalizeString);
knownGlobals.push(isAsciiString);
}

if (global.DTRACE_HTTP_SERVER_RESPONSE) {
knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE);
knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST);
Expand Down
36 changes: 36 additions & 0 deletions test/simple/test-v8-externalize-string.js
@@ -0,0 +1,36 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

// Flags: --expose_externalize_string

var common = require('../common');
var assert = require('assert');

assert(typeof externalizeString === 'function',
'Run this test with --expose_externalize_string.');

var str = '中';
var buf = new Buffer(str);
assert.equal(buf.toString('hex'), 'e4b8ad');

externalizeString(str, true); // force two bytes string
var extbuf = new Buffer(str); // convert string to utf8 buffer
assert.equal(extbuf.toString('hex'), 'e4b8ad');

0 comments on commit cfc2689

Please sign in to comment.