Skip to content

Commit d3c931d

Browse files
committed
Expose the script id from StackFrame.
Currently V8 API use two ways for a script recognition; - script file name - id The first one is not unique and the second is accessible only from v8::Script object which makes it unusable. This patch exposes script id from frame so we can do deterministic association between them.
1 parent f820d44 commit d3c931d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/3rdparty/v8/include/v8.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,12 @@ class V8EXPORT StackTrace {
773773
kIsEval = 1 << 4,
774774
kIsConstructor = 1 << 5,
775775
kScriptNameOrSourceURL = 1 << 6,
776+
#ifdef QT_BUILD_SCRIPT_LIB
777+
kScriptId = 1 << 7,
778+
kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName | kScriptId,
779+
#else
776780
kOverview = kLineNumber | kColumnOffset | kScriptName | kFunctionName,
781+
#endif
777782
kDetailed = kOverview | kIsEval | kIsConstructor | kScriptNameOrSourceURL
778783
};
779784

@@ -833,6 +838,14 @@ class V8EXPORT StackFrame {
833838
*/
834839
Local<String> GetScriptName() const;
835840

841+
#ifdef QT_BUILD_SCRIPT_LIB
842+
/**
843+
* Returns the id of the resource that contains the script for the
844+
* function for this StackFrame.
845+
*/
846+
Local<Value> GetScriptId() const;
847+
#endif
848+
836849
/**
837850
* Returns the name of the resource that contains the script for the
838851
* function for this StackFrame or sourceURL value if the script name

src/3rdparty/v8/src/api.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,20 @@ Local<String> StackFrame::GetScriptName() const {
19421942
return scope.Close(Local<String>::Cast(Utils::ToLocal(name)));
19431943
}
19441944

1945+
#ifdef QT_BUILD_SCRIPT_LIB
1946+
Local<Value> StackFrame::GetScriptId() const {
1947+
i::Isolate* isolate = i::Isolate::Current();
1948+
if (IsDeadCheck(isolate, "v8::StackFrame::GetScriptId()")) return Local<Value>();
1949+
ENTER_V8(isolate);
1950+
HandleScope scope;
1951+
i::Handle<i::JSObject> self = Utils::OpenHandle(this);
1952+
i::Handle<i::Object> id = GetProperty(self, "scriptId");
1953+
if (!id->IsNumber()) {
1954+
return Local<Value>();
1955+
}
1956+
return scope.Close(Utils::ToLocal(id));
1957+
}
1958+
#endif
19451959

19461960
Local<String> StackFrame::GetScriptNameOrSourceURL() const {
19471961
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();

src/3rdparty/v8/src/top.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace(
197197
Handle<String> column_key = factory()->LookupAsciiSymbol("column");
198198
Handle<String> line_key = factory()->LookupAsciiSymbol("lineNumber");
199199
Handle<String> script_key = factory()->LookupAsciiSymbol("scriptName");
200+
#ifdef QT_BUILD_SCRIPT_LIB
201+
Handle<String> script_id_key = factory()->LookupAsciiSymbol("scriptId");
202+
#endif
200203
Handle<String> name_or_source_url_key =
201204
factory()->LookupAsciiSymbol("nameOrSourceURL");
202205
Handle<String> script_name_or_source_url_key =
@@ -249,6 +252,13 @@ Handle<JSArray> Isolate::CaptureCurrentStackTrace(
249252
SetLocalPropertyNoThrow(stackFrame, script_key, script_name);
250253
}
251254

255+
#ifdef QT_BUILD_SCRIPT_LIB
256+
if (options & StackTrace::kScriptId) {
257+
Handle<Object> script_id(script->id());
258+
SetLocalPropertyNoThrow(stackFrame, script_id_key, script_id);
259+
}
260+
#endif
261+
252262
if (options & StackTrace::kScriptNameOrSourceURL) {
253263
Handle<Object> script_name(script->name(), this);
254264
Handle<JSValue> script_wrapper = GetScriptWrapper(script);

0 commit comments

Comments
 (0)