Skip to content

Commit 6c00432

Browse files
committed
Update V8 to 6.6.346.27
1 parent fbe92a9 commit 6c00432

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let package = Package(
4646
dependencies: ["CV8", "Platform", "JavaScript"]),
4747
.target(
4848
name: "V8",
49-
dependencies: ["CV8Platform", "V8API", "JavaScript"]),
49+
dependencies: ["CV8Platform", "V8API", "Platform", "JavaScript"]),
5050
.target(
5151
name: "JavaScript",
5252
dependencies: []),

Sources/CV8/c_v8.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,17 @@ extern "C" {
236236
HandleScope handle_scope(isolate);
237237

238238
auto object = value->Get(isolate)->ToObject();
239+
auto context = isolate->GetEnteredContext();
239240
auto key = String::NewFromUtf8(isolate, keyPtr);
240-
auto result = object->GetRealNamedProperty(key);
241+
242+
auto result = object->GetRealNamedProperty(context, key);
241243

242244
if (result.IsEmpty()) {
243245
if (exception != nullptr) {
244246
*exception = new Global<Value>(isolate, trycatch.Exception());
245247
}
246248
return nullptr;
247249
}
248-
return new Global<Value>(isolate, result);
250+
return new Global<Value>(isolate, result.ToLocalChecked());
249251
}
250252
}

Sources/CV8Platform/c_v8_platform.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,17 @@
99
* *
1010
******************************************************************************/
1111

12-
#include <stdlib.h> // malloc, free
13-
#include <string.h> // memset, memcpy
12+
#include "c_v8_platform.h"
13+
1414
#include <libplatform/libplatform.h>
1515
#include <v8.h>
16-
#include "c_v8_platform.h"
1716

1817
using namespace v8;
1918

20-
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
21-
public:
22-
virtual void *Allocate(size_t length){
23-
void *data = AllocateUninitialized(length);
24-
return data == NULL ? data : memset(data, 0, length);
25-
}
26-
virtual void *AllocateUninitialized(size_t length) { return malloc(length); }
27-
virtual void Free(void *data, size_t) { free(data); }
28-
};
29-
3019
extern "C" {
31-
ArrayBufferAllocator bufferAllocator;
32-
33-
void* initialize() {
34-
V8::InitializeICU();
20+
void* initialize(const char *exec_path) {
21+
V8::InitializeICUDefaultLocation(exec_path);
22+
v8::V8::InitializeExternalStartupData(exec_path);
3523
auto platform = platform::CreateDefaultPlatform();
3624
V8::InitializePlatform(platform);
3725
V8::Initialize();
@@ -46,7 +34,8 @@ extern "C" {
4634

4735
void* createIsolate() {
4836
Isolate::CreateParams create_params;
49-
create_params.array_buffer_allocator = &bufferAllocator;
37+
create_params.array_buffer_allocator =
38+
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
5039
return Isolate::New(create_params);
5140
}
5241

Sources/CV8Platform/include/c_v8_platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
#endif
2121

2222
// global
23-
void * _Nonnull initialize();
23+
void * _Nonnull initialize(const char * _Nonnull exec_path);
2424
void dispose(void * _Nonnull platform);
2525
// isolater
2626
void * _Nonnull createIsolate();

Sources/V8/JSRuntime.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import CV8Platform
1313
import JavaScript
14+
import Platform
1415

1516
@_exported import V8API
1617

@@ -22,11 +23,14 @@ public class JSRuntime {
2223
return JSRuntime()
2324
}()
2425

26+
// The whole V8API & V8 split is caused
27+
// by difference in the initialization
28+
// between standalone v8 and node.js,
29+
// so this way we can reuse the api
2530
public required init() {
26-
// The whole V8API & V8 split is caused
27-
// by difference in this initialization
28-
// between standalone v8 and node.js
29-
self.platform = initialize()
31+
// used to load snapshot_blob, natives_blob, icudtl.dat
32+
let libsPath = Environment["NODE_PATH"] ?? "/usr/local/lib/"
33+
self.platform = initialize(libsPath)
3034
self.isolate = createIsolate()
3135
}
3236

0 commit comments

Comments
 (0)