Skip to content

Commit 09c10dd

Browse files
committed
[V8] Update to 7.0.276.28
1 parent 32217f1 commit 09c10dd

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,8 @@ assertEqual("\(result)", "result string")
3535

3636
#### V8
3737

38-
Default homebrew formula is outdated, please remove it first
39-
4038
```bash
41-
brew remove v8
42-
```
43-
44-
```bash
45-
brew tap tris-brew/macos
46-
brew install libv8
39+
brew install v8
4740
```
4841

4942
#### JavaScriptCore

Sources/CV8/c_v8.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,25 @@ extern "C" {
9292
Local<Context> context = globalContext->Get(isolate);
9393
Context::Scope context_scope(context);
9494
Local<String> source = String::NewFromUtf8(isolate, scriptPtr);
95-
Local<Script> script = Script::Compile(source);
96-
Local<Value> result = script->Run();
95+
MaybeLocal<Script> maybeScript = Script::Compile(context, source);
96+
97+
if(maybeScript.IsEmpty()) {
98+
if (exception != nullptr) {
99+
*exception = new Global<Value>(isolate, trycatch.Exception());
100+
}
101+
return nullptr;
102+
}
103+
104+
Local<Script> script = maybeScript.ToLocalChecked();
105+
MaybeLocal<Value> result = script->Run(context);
97106

98107
if (result.IsEmpty()) {
99108
if (exception != nullptr) {
100109
*exception = new Global<Value>(isolate, trycatch.Exception());
101110
}
102111
return nullptr;
103112
}
104-
return new Global<Value>(isolate, result);
113+
return new Global<Value>(isolate, result.ToLocalChecked());
105114
}
106115

107116
void disposeValue(void* pointer) {
@@ -113,15 +122,17 @@ extern "C" {
113122
return scoped->ToInteger()->IntegerValue();
114123
}
115124

116-
int getUtf8StringLength(void* isolate, void* value) {
125+
int getUtf8StringLength(void* isolatePtr, void* value) {
126+
auto isolate = reinterpret_cast<Isolate*>(isolatePtr);
117127
GlobalValue scoped(isolate, value);
118-
String::Utf8Value utf8(*scoped);
128+
String::Utf8Value utf8(isolate, *scoped);
119129
return utf8.length();
120130
}
121131

122-
void copyUtf8String(void* isolate, void* value, void* buffer, int count) {
132+
void copyUtf8String(void* isolatePtr, void* value, void* buffer, int count) {
133+
auto isolate = reinterpret_cast<Isolate*>(isolatePtr);
123134
GlobalValue scoped(isolate, value);
124-
String::Utf8Value utf8(*scoped);
135+
String::Utf8Value utf8(isolate, *scoped);
125136
memcpy(buffer, *utf8, count);
126137
}
127138

Tests/V8Tests/V8Tests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ final class V8Tests: TestCase {
2323
assertThrowsError(try context.evaluate("x()")) { error in
2424
assertEqual("\(error)", "ReferenceError: x is not defined")
2525
}
26+
27+
assertThrowsError(try context.evaluate("{")) { error in
28+
assertEqual("\(error)", "SyntaxError: Unexpected end of input")
29+
}
2630
}
2731

2832
func testFunction() {

0 commit comments

Comments
 (0)