From 4313cfbc4f7a59e4af459825a7bb4ca1f7a5027b Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 22 Dec 2016 18:11:49 +0000 Subject: [PATCH] Let task.execute accept raw UTF-8 bytes, for the sake of the tests. Missing #include. Minor cleanup. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3359 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/core.js | 1 - src/Serialize.cpp | 6 +++--- src/Socket.h | 1 + src/Task.cpp | 15 +++++++++++++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/core/core.js b/core/core.js index 9a969e411..969e935e9 100644 --- a/core/core.js +++ b/core/core.js @@ -1,6 +1,5 @@ "use strict"; - require("encoding-indexes"); require("encoding"); diff --git a/src/Serialize.cpp b/src/Serialize.cpp index 33d8c01dd..3b70c87c5 100644 --- a/src/Serialize.cpp +++ b/src/Serialize.cpp @@ -82,9 +82,9 @@ bool Serialize::storeInternal(Task* task, std::vector& buffer, v8::Handle< buffer.insert(buffer.end(), *utf8, *utf8 + utf8.length()); } else if (value->IsUint8Array()) { writeInt32(buffer, kUint8Array); - v8::Handle array = v8::Handle::Cast(value); - char* data = reinterpret_cast(array->GetContents().Data()); - size_t length = array->GetContents().ByteLength(); + v8::Handle array = v8::Handle::Cast(value); + char* data = reinterpret_cast(array->Buffer()->GetContents().Data()); + size_t length = array->Buffer()->GetContents().ByteLength(); writeInt32(buffer, length); buffer.insert(buffer.end(), data, data + length); } else if (value->IsArray()) { diff --git a/src/Socket.h b/src/Socket.h index f7dc37d19..fdb627bcc 100644 --- a/src/Socket.h +++ b/src/Socket.h @@ -1,6 +1,7 @@ #ifndef INCLUDED_Socket #define INCLUDED_Socket +#include #include #include #include diff --git a/src/Task.cpp b/src/Task.cpp index cd678d176..2dad3f92d 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -676,9 +676,20 @@ void Task::onReceivePacket(int packetType, const char* begin, size_t length, voi tryCatch.SetVerbose(true); v8::Handle value = Serialize::load(to, from, std::vector(begin + sizeof(promiseid_t), begin + length)); v8::Handle object = v8::Handle::Cast(value); - v8::Handle source = v8::Handle::Cast(object->Get(v8::String::NewFromUtf8(to->_isolate, "source"))); + v8::Handle source = v8::Handle::Cast(object->Get(v8::String::NewFromUtf8(to->_isolate, "source"))); + v8::Handle stringSource; + if (source->IsArrayBufferView()) { + v8::Handle array = v8::Handle::Cast(source); + stringSource = v8::String::NewFromUtf8( + to->_isolate, + reinterpret_cast(array->Buffer()->GetContents().Data()), + v8::String::kNormalString, + array->Buffer()->GetContents().ByteLength()); + } else if (source->IsString()) { + stringSource = v8::Handle::Cast(source); + } v8::Handle name = v8::Handle::Cast(object->Get(v8::String::NewFromUtf8(to->_isolate, "name"))); - to->executeSource(source, name); + to->executeSource(stringSource, name); if (tryCatch.HasCaught()) { sendPromiseReject(to, from, promise, Serialize::store(to, tryCatch)); }