Skip to content

Commit c3d3c8e

Browse files
committed
src: fixups after v8 upgrade
* v8::Platform has a new MonotonicallyIncreasingTime() method, implement it. * The ASCII apocalypse continues with the replacement of external ASCII strings with external one byte strings.
1 parent 5a43848 commit c3d3c8e

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/node_v8_platform.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ void Platform::CallOnForegroundThread(Isolate* isolate, Task* task) {
8181
}
8282

8383

84+
double Platform::MonotonicallyIncreasingTime() {
85+
// uv_hrtime() returns a uint64_t but doubles can only represent integrals up
86+
// to 2^53 accurately. Take steps to prevent loss of precision on overflow.
87+
const uint64_t timestamp = uv_hrtime();
88+
const uint64_t billion = 1000 * 1000 * 1000;
89+
const uint64_t seconds = timestamp / billion;
90+
const uint64_t nanoseconds = timestamp % billion;
91+
return seconds + 1.0 / nanoseconds;
92+
}
93+
94+
8495
void Platform::WorkerBody(void* arg) {
8596
Platform* p = static_cast<Platform*>(arg);
8697

src/node_v8_platform.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Platform : public v8::Platform {
5555
void CallOnBackgroundThread(v8::Task* task,
5656
ExpectedRuntime expected_runtime);
5757
void CallOnForegroundThread(v8::Isolate* isolate, v8::Task* task);
58+
double MonotonicallyIncreasingTime();
5859

5960
protected:
6061
static void WorkerBody(void* arg);

src/string_bytes.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ExternString: public ResourceType {
106106
};
107107

108108

109-
typedef ExternString<String::ExternalAsciiStringResource,
109+
typedef ExternString<String::ExternalOneByteStringResource,
110110
char> ExternOneByteString;
111111
typedef ExternString<String::ExternalStringResource,
112112
uint16_t> ExternTwoByteString;
@@ -270,9 +270,9 @@ bool StringBytes::GetExternalParts(Isolate* isolate,
270270

271271
Local<String> str = val.As<String>();
272272

273-
if (str->IsExternalAscii()) {
274-
const String::ExternalAsciiStringResource* ext;
275-
ext = str->GetExternalAsciiStringResource();
273+
if (str->IsExternalOneByte()) {
274+
const String::ExternalOneByteStringResource* ext;
275+
ext = str->GetExternalOneByteStringResource();
276276
*data = ext->data();
277277
*len = ext->length();
278278
return true;

0 commit comments

Comments
 (0)