Skip to content

Commit 469f2d5

Browse files
committed
Merge branch 'issue-6526-get-frame-and-show-warnings' into 'master'
Issue 6526 - get rid of the usage of deprecated V8 API and show warnings if it happens again See merge request eyeo/adblockplus/libadblockplus!9
2 parents 0233c1b + 32e440a commit 469f2d5

2 files changed

Lines changed: 46 additions & 6 deletions

File tree

src/ConsoleJsObject.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "JsContext.h"
2424
#include "Utils.h"
2525
#include <AdblockPlus/Platform.h>
26+
#include "v8-compat-api.h"
27+
28+
using namespace AdblockPlus::V8CompatApi;
2629

2730
namespace
2831
{
@@ -42,8 +45,9 @@ namespace
4245
}
4346

4447
std::stringstream source;
45-
v8::Local<v8::StackFrame> frame = v8::StackTrace::CurrentStackTrace(arguments.GetIsolate(), 1)->GetFrame(0);
46-
source << AdblockPlus::Utils::FromV8String(arguments.GetIsolate(), frame->GetScriptName());
48+
auto isolate = arguments.GetIsolate();
49+
v8::Local<v8::StackFrame> frame = StackTrace_GetFrame(isolate, v8::StackTrace::CurrentStackTrace(isolate, 1), 0);
50+
source << AdblockPlus::Utils::FromV8String(isolate, frame->GetScriptName());
4751
source << ":" << frame->GetLineNumber();
4852

4953
jsEngine->GetPlatform().WithLogSystem(
@@ -84,19 +88,20 @@ namespace
8488
const AdblockPlus::JsContext context(*jsEngine);
8589
AdblockPlus::JsValueList converted = jsEngine->ConvertArguments(arguments);
8690

91+
auto isolate = arguments.GetIsolate();
8792
std::stringstream traceback;
88-
v8::Local<v8::StackTrace> frames = v8::StackTrace::CurrentStackTrace(arguments.GetIsolate(), 100);
93+
v8::Local<v8::StackTrace> frames = v8::StackTrace::CurrentStackTrace(isolate, 100);
8994
for (int i = 0, l = frames->GetFrameCount(); i < l; i++)
9095
{
91-
v8::Local<v8::StackFrame> frame = frames->GetFrame(i);
96+
v8::Local<v8::StackFrame> frame = StackTrace_GetFrame(isolate, frames, i);
9297
traceback << (i + 1) << ": ";
93-
std::string name = AdblockPlus::Utils::FromV8String(arguments.GetIsolate(), frame->GetFunctionName());
98+
std::string name = AdblockPlus::Utils::FromV8String(isolate, frame->GetFunctionName());
9499
if (name.size())
95100
traceback << name;
96101
else
97102
traceback << "/* anonymous */";
98103
traceback << "() at ";
99-
traceback << AdblockPlus::Utils::FromV8String(arguments.GetIsolate(), frame->GetScriptName());
104+
traceback << AdblockPlus::Utils::FromV8String(isolate, frame->GetScriptName());
100105
traceback << ":" << frame->GetLineNumber();
101106
traceback << std::endl;
102107
}

src/v8-compat-api.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of Adblock Plus <https://adblockplus.org/>,
3+
* Copyright (C) 2006-present eyeo GmbH
4+
*
5+
* Adblock Plus is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License version 3 as
7+
* published by the Free Software Foundation.
8+
*
9+
* Adblock Plus is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#pragma once
19+
20+
#include <v8.h>
21+
22+
namespace AdblockPlus
23+
{
24+
namespace V8CompatApi
25+
{
26+
v8::Local<v8::StackFrame> StackTrace_GetFrame(v8::Isolate* isolate, const v8::Local<v8::StackTrace>& stackTrace, uint32_t index)
27+
{
28+
#if V8_MAJOR_VERSION == 6 && V8_MINOR_VERSION <= 7
29+
return stackTrace->GetFrame(index);
30+
#else
31+
return stackTrace->GetFrame(isolate, index);
32+
#endif
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)