2013-01-03 18:24:24 +01:00
|
|
|
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
|
2012-04-03 03:34:16 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2013-10-16 02:25:38 +02:00
|
|
|
// MSVC++ requires this to be set before any other includes to get M_PI.
|
|
|
|
// Otherwise there will be compile errors in wtf/MathExtras.h.
|
|
|
|
#define _USE_MATH_DEFINES
|
|
|
|
|
2024-04-12 17:37:33 +02:00
|
|
|
#include <limits>
|
2012-10-29 22:46:02 +01:00
|
|
|
#include <map>
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
2012-04-03 03:34:16 +02:00
|
|
|
#include <string>
|
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
#include "base/command_line.h"
|
2022-02-21 23:23:40 +01:00
|
|
|
#include "build/build_config.h"
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings for MSVC and Clang. See http://crbug.com/585142.
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic error "-Wdeprecated-declarations"
|
|
|
|
#else
|
2016-02-08 19:47:18 +01:00
|
|
|
#pragma warning(push)
|
2017-05-17 11:29:28 +02:00
|
|
|
#pragma warning(default : 4996)
|
2016-02-08 19:47:18 +01:00
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|
2016-02-08 19:47:18 +01:00
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
#include "base/auto_reset.h"
|
2023-01-30 18:43:54 +01:00
|
|
|
#include "base/functional/bind.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/lazy_instance.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_number_conversions.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/common/app_manager.h"
|
|
|
|
#include "cef/libcef/common/cef_switches.h"
|
|
|
|
#include "cef/libcef/common/task_runner_impl.h"
|
|
|
|
#include "cef/libcef/common/tracker.h"
|
|
|
|
#include "cef/libcef/renderer/blink_glue.h"
|
|
|
|
#include "cef/libcef/renderer/browser_impl.h"
|
|
|
|
#include "cef/libcef/renderer/render_frame_util.h"
|
|
|
|
#include "cef/libcef/renderer/thread_util.h"
|
|
|
|
#include "cef/libcef/renderer/v8_impl.h"
|
2023-04-04 20:00:13 +02:00
|
|
|
#include "third_party/abseil-cpp/absl/base/attributes.h"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "third_party/blink/public/web/blink.h"
|
|
|
|
#include "third_party/blink/public/web/web_frame.h"
|
|
|
|
#include "third_party/blink/public/web/web_local_frame.h"
|
2022-06-17 15:28:55 +02:00
|
|
|
#include "third_party/blink/public/web/web_script_controller.h"
|
2013-07-24 22:15:18 +02:00
|
|
|
#include "url/gurl.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
static const char kCefTrackObject[] = "Cef::TrackObject";
|
2024-04-12 17:37:33 +02:00
|
|
|
constexpr int32_t kMaxInt32 = std::numeric_limits<int32_t>::max();
|
|
|
|
constexpr uint32_t kMaxInt32AsUint32 = static_cast<uint32_t>(kMaxInt32);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
void MessageListenerCallbackImpl(v8::Handle<v8::Message> message,
|
|
|
|
v8::Handle<v8::Value> data);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
// The following *Private functions are convenience wrappers for methods on
|
|
|
|
// v8::Object with the corresponding names.
|
|
|
|
// Based on extensions/renderer/object_backed_native_handler.cc.
|
|
|
|
|
|
|
|
void SetPrivate(v8::Local<v8::Context> context,
|
|
|
|
v8::Local<v8::Object> obj,
|
|
|
|
const char* key,
|
|
|
|
v8::Local<v8::Value> value) {
|
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2019-01-17 10:56:52 +01:00
|
|
|
obj->SetPrivate(context,
|
|
|
|
v8::Private::ForApi(
|
|
|
|
isolate, v8::String::NewFromUtf8(
|
|
|
|
isolate, key, v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked()),
|
|
|
|
value)
|
2015-12-09 17:10:16 +01:00
|
|
|
.FromJust();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetPrivate(v8::Local<v8::Context> context,
|
|
|
|
v8::Local<v8::Object> obj,
|
|
|
|
const char* key,
|
|
|
|
v8::Local<v8::Value>* result) {
|
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2017-05-17 11:29:28 +02:00
|
|
|
return obj
|
2019-01-17 10:56:52 +01:00
|
|
|
->GetPrivate(context,
|
|
|
|
v8::Private::ForApi(
|
|
|
|
isolate, v8::String::NewFromUtf8(
|
|
|
|
isolate, key, v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked()))
|
2015-12-09 17:10:16 +01:00
|
|
|
.ToLocal(result);
|
|
|
|
}
|
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
// Chromium uses the default Isolate for the main render process thread and a
|
|
|
|
// new Isolate for each WebWorker thread. Continue this pattern by tracking
|
|
|
|
// Isolate information on a per-thread basis. This implementation will need to
|
|
|
|
// be re-worked (perhaps using a map keyed on v8::Isolate::GetCurrent()) if
|
|
|
|
// in the future Chromium begins using the same Isolate across multiple threads.
|
|
|
|
class CefV8IsolateManager;
|
|
|
|
ABSL_CONST_INIT thread_local CefV8IsolateManager* g_isolate_manager = nullptr;
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
// Manages memory and state information associated with a single Isolate.
|
|
|
|
class CefV8IsolateManager {
|
2012-10-29 22:46:02 +01:00
|
|
|
public:
|
2013-01-03 18:24:24 +01:00
|
|
|
CefV8IsolateManager()
|
2023-04-04 20:00:13 +02:00
|
|
|
: resetter_(&g_isolate_manager, this),
|
|
|
|
isolate_(v8::Isolate::GetCurrent()),
|
2024-01-20 23:48:57 +01:00
|
|
|
task_runner_(CEF_RENDER_TASK_RUNNER()) {
|
2013-01-03 18:24:24 +01:00
|
|
|
DCHECK(isolate_);
|
|
|
|
DCHECK(task_runner_.get());
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
2023-04-04 20:00:13 +02:00
|
|
|
~CefV8IsolateManager() = default;
|
|
|
|
|
|
|
|
static CefV8IsolateManager* Get() { return g_isolate_manager; }
|
|
|
|
|
|
|
|
void Destroy() {
|
2013-01-03 18:24:24 +01:00
|
|
|
DCHECK_EQ(isolate_, v8::Isolate::GetCurrent());
|
|
|
|
DCHECK(context_map_.empty());
|
2023-04-04 20:00:13 +02:00
|
|
|
delete this;
|
2013-01-03 18:24:24 +01:00
|
|
|
}
|
2012-10-29 22:46:02 +01:00
|
|
|
|
|
|
|
scoped_refptr<CefV8ContextState> GetContextState(
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Context> context) {
|
2013-01-03 18:24:24 +01:00
|
|
|
DCHECK_EQ(isolate_, v8::Isolate::GetCurrent());
|
2013-03-12 21:23:24 +01:00
|
|
|
DCHECK(context.IsEmpty() || isolate_ == context->GetIsolate());
|
2013-01-03 18:24:24 +01:00
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
if (context.IsEmpty()) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (isolate_->InContext()) {
|
2013-12-17 23:04:35 +01:00
|
|
|
context = isolate_->GetCurrentContext();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2012-10-29 22:46:02 +01:00
|
|
|
return scoped_refptr<CefV8ContextState>();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2017-05-09 21:29:24 +02:00
|
|
|
int hash = context->Global()->GetIdentityHash();
|
|
|
|
ContextMap::const_iterator it = context_map_.find(hash);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it != context_map_.end()) {
|
2017-05-09 21:29:24 +02:00
|
|
|
return it->second;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-10-29 22:46:02 +01:00
|
|
|
|
2017-05-09 21:29:24 +02:00
|
|
|
scoped_refptr<CefV8ContextState> state = new CefV8ContextState();
|
|
|
|
context_map_.insert(std::make_pair(hash, state));
|
2012-10-29 22:46:02 +01:00
|
|
|
|
2017-05-09 21:29:24 +02:00
|
|
|
return state;
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
void ReleaseContext(v8::Local<v8::Context> context) {
|
2013-01-03 18:24:24 +01:00
|
|
|
DCHECK_EQ(isolate_, v8::Isolate::GetCurrent());
|
2013-12-17 23:04:35 +01:00
|
|
|
DCHECK_EQ(isolate_, context->GetIsolate());
|
2013-01-03 18:24:24 +01:00
|
|
|
|
2017-05-09 21:29:24 +02:00
|
|
|
int hash = context->Global()->GetIdentityHash();
|
|
|
|
ContextMap::iterator it = context_map_.find(hash);
|
|
|
|
if (it != context_map_.end()) {
|
|
|
|
it->second->Detach();
|
|
|
|
context_map_.erase(it);
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 21:49:43 +01:00
|
|
|
void AddGlobalTrackObject(CefTrackNode* object) {
|
2013-01-03 18:24:24 +01:00
|
|
|
DCHECK_EQ(isolate_, v8::Isolate::GetCurrent());
|
2012-10-30 21:49:43 +01:00
|
|
|
global_manager_.Add(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteGlobalTrackObject(CefTrackNode* object) {
|
2013-01-03 18:24:24 +01:00
|
|
|
DCHECK_EQ(isolate_, v8::Isolate::GetCurrent());
|
2012-10-30 21:49:43 +01:00
|
|
|
global_manager_.Delete(object);
|
|
|
|
}
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
void SetUncaughtExceptionStackSize(int stack_size) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (stack_size <= 0) {
|
2013-01-03 18:24:24 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-01-03 18:24:24 +01:00
|
|
|
|
|
|
|
if (!message_listener_registered_) {
|
2016-01-06 20:20:54 +01:00
|
|
|
isolate_->AddMessageListener(&MessageListenerCallbackImpl);
|
2013-01-03 18:24:24 +01:00
|
|
|
message_listener_registered_ = true;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
isolate_->SetCaptureStackTraceForUncaughtExceptions(
|
|
|
|
true, stack_size, v8::StackTrace::kDetailed);
|
2013-01-03 18:24:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetWorkerAttributes(int worker_id, const GURL& worker_url) {
|
|
|
|
worker_id_ = worker_id;
|
|
|
|
worker_url_ = worker_url;
|
|
|
|
}
|
|
|
|
|
2013-03-12 21:23:24 +01:00
|
|
|
v8::Isolate* isolate() const { return isolate_; }
|
2017-09-21 13:57:40 +02:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
|
2013-01-03 18:24:24 +01:00
|
|
|
return task_runner_;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
int worker_id() const { return worker_id_; }
|
2013-01-03 18:24:24 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
const GURL& worker_url() const { return worker_url_; }
|
2013-01-03 18:24:24 +01:00
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
private:
|
2023-04-04 20:00:13 +02:00
|
|
|
const base::AutoReset<CefV8IsolateManager*> resetter_;
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
v8::Isolate* isolate_;
|
2017-09-21 13:57:40 +02:00
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
2013-01-03 18:24:24 +01:00
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
using ContextMap = std::map<int, scoped_refptr<CefV8ContextState>>;
|
2012-10-29 22:46:02 +01:00
|
|
|
ContextMap context_map_;
|
|
|
|
|
2012-10-30 21:49:43 +01:00
|
|
|
// Used for globally tracked objects that are not associated with a particular
|
|
|
|
// context.
|
|
|
|
CefTrackManager global_manager_;
|
2013-01-03 18:24:24 +01:00
|
|
|
|
|
|
|
// True if the message listener has been registered.
|
2024-01-20 23:48:57 +01:00
|
|
|
bool message_listener_registered_ = false;
|
2013-01-03 18:24:24 +01:00
|
|
|
|
|
|
|
// Attributes associated with WebWorker threads.
|
2024-01-20 23:48:57 +01:00
|
|
|
int worker_id_ = 0;
|
2013-01-03 18:24:24 +01:00
|
|
|
GURL worker_url_;
|
2012-10-29 22:46:02 +01:00
|
|
|
};
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
class V8TrackObject : public CefTrackNode {
|
|
|
|
public:
|
2024-01-20 23:48:57 +01:00
|
|
|
explicit V8TrackObject(v8::Isolate* isolate) : isolate_(isolate) {
|
2013-12-17 23:04:35 +01:00
|
|
|
DCHECK(isolate_);
|
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
2012-10-30 21:49:43 +01:00
|
|
|
static_cast<int>(sizeof(V8TrackObject)));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2024-01-20 23:48:57 +01:00
|
|
|
~V8TrackObject() override {
|
2013-12-17 23:04:35 +01:00
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
2012-10-30 21:49:43 +01:00
|
|
|
-static_cast<int>(sizeof(V8TrackObject)) - external_memory_);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
inline int GetExternallyAllocatedMemory() { return external_memory_; }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
int AdjustExternallyAllocatedMemory(int change_in_bytes) {
|
|
|
|
int new_value = external_memory_ + change_in_bytes;
|
|
|
|
if (new_value < 0) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "External memory usage cannot be less than 0 bytes";
|
2012-04-03 03:34:16 +02:00
|
|
|
change_in_bytes = -(external_memory_);
|
|
|
|
new_value = 0;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (change_in_bytes != 0) {
|
2013-12-17 23:04:35 +01:00
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
external_memory_ = new_value;
|
|
|
|
|
|
|
|
return new_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SetAccessor(CefRefPtr<CefV8Accessor> accessor) {
|
|
|
|
accessor_ = accessor;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
inline CefRefPtr<CefV8Accessor> GetAccessor() { return accessor_; }
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2016-10-27 19:23:56 +02:00
|
|
|
inline void SetInterceptor(CefRefPtr<CefV8Interceptor> interceptor) {
|
|
|
|
interceptor_ = interceptor;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
inline CefRefPtr<CefV8Interceptor> GetInterceptor() { return interceptor_; }
|
2016-10-27 19:23:56 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
inline void SetHandler(CefRefPtr<CefV8Handler> handler) {
|
|
|
|
handler_ = handler;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
inline CefRefPtr<CefV8Handler> GetHandler() { return handler_; }
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2017-02-09 23:07:43 +01:00
|
|
|
inline void SetUserData(CefRefPtr<CefBaseRefCounted> user_data) {
|
2012-04-03 03:34:16 +02:00
|
|
|
user_data_ = user_data;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
inline CefRefPtr<CefBaseRefCounted> GetUserData() { return user_data_; }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Attach this track object to the specified V8 object.
|
2017-05-17 11:29:28 +02:00
|
|
|
void AttachTo(v8::Local<v8::Context> context, v8::Local<v8::Object> object) {
|
2015-12-09 17:10:16 +01:00
|
|
|
SetPrivate(context, object, kCefTrackObject,
|
|
|
|
v8::External::New(isolate_, this));
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the track object for the specified V8 object.
|
2015-12-09 17:10:16 +01:00
|
|
|
static V8TrackObject* Unwrap(v8::Local<v8::Context> context,
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Object> object) {
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::Local<v8::Value> value;
|
2023-01-12 21:55:21 +01:00
|
|
|
if (GetPrivate(context, object, kCefTrackObject, &value) &&
|
|
|
|
value->IsExternal()) {
|
2012-11-30 20:08:20 +01:00
|
|
|
return static_cast<V8TrackObject*>(v8::External::Cast(*value)->Value());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate_;
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefV8Accessor> accessor_;
|
2016-10-27 19:23:56 +02:00
|
|
|
CefRefPtr<CefV8Interceptor> interceptor_;
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefV8Handler> handler_;
|
2017-02-09 23:07:43 +01:00
|
|
|
CefRefPtr<CefBaseRefCounted> user_data_;
|
2024-01-20 23:48:57 +01:00
|
|
|
int external_memory_ = 0;
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class V8TrackString : public CefTrackNode {
|
|
|
|
public:
|
|
|
|
explicit V8TrackString(const std::string& str) : string_(str) {}
|
|
|
|
const char* GetString() { return string_.c_str(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string string_;
|
|
|
|
};
|
|
|
|
|
2018-04-10 21:37:33 +02:00
|
|
|
class V8TrackArrayBuffer : public CefTrackNode {
|
|
|
|
public:
|
|
|
|
explicit V8TrackArrayBuffer(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
CefRefPtr<CefV8ArrayBufferReleaseCallback> release_callback)
|
2021-03-23 20:58:17 +01:00
|
|
|
: isolate_(isolate), release_callback_(release_callback) {
|
2018-04-10 21:37:33 +02:00
|
|
|
DCHECK(isolate_);
|
2018-10-10 15:12:22 +02:00
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
|
|
|
static_cast<int>(sizeof(V8TrackArrayBuffer)));
|
2018-04-10 21:37:33 +02:00
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
~V8TrackArrayBuffer() override {
|
2018-04-10 21:37:33 +02:00
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
|
|
|
-static_cast<int>(sizeof(V8TrackArrayBuffer)));
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8ArrayBufferReleaseCallback> GetReleaseCallback() {
|
|
|
|
return release_callback_;
|
|
|
|
}
|
|
|
|
|
2018-10-10 15:12:22 +02:00
|
|
|
// Attach this track object to the specified V8 object.
|
|
|
|
void AttachTo(v8::Local<v8::Context> context,
|
|
|
|
v8::Local<v8::ArrayBuffer> arrayBuffer) {
|
|
|
|
SetPrivate(context, arrayBuffer, kCefTrackObject,
|
|
|
|
v8::External::New(isolate_, this));
|
|
|
|
}
|
|
|
|
|
2018-04-10 21:37:33 +02:00
|
|
|
// Retrieve the track object for the specified V8 object.
|
|
|
|
static V8TrackArrayBuffer* Unwrap(v8::Local<v8::Context> context,
|
|
|
|
v8::Local<v8::Object> object) {
|
|
|
|
v8::Local<v8::Value> value;
|
2023-01-12 21:55:21 +01:00
|
|
|
if (GetPrivate(context, object, kCefTrackObject, &value) &&
|
|
|
|
value->IsExternal()) {
|
2018-04-10 21:37:33 +02:00
|
|
|
return static_cast<V8TrackArrayBuffer*>(
|
|
|
|
v8::External::Cast(*value)->Value());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-04-10 21:37:33 +02:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
CefRefPtr<CefV8ArrayBufferReleaseCallback> release_callback_;
|
|
|
|
};
|
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
// Object wrapped in a v8::External and passed as the Data argument to
|
|
|
|
// v8::FunctionTemplate::New.
|
|
|
|
class V8FunctionData {
|
|
|
|
public:
|
|
|
|
static v8::Local<v8::External> Create(v8::Isolate* isolate,
|
|
|
|
const CefString& function_name,
|
2018-02-16 18:56:20 +01:00
|
|
|
CefRefPtr<CefV8Handler> handler) {
|
2016-02-05 01:49:19 +01:00
|
|
|
// |data| will be deleted if/when the returned v8::External is GC'd.
|
|
|
|
V8FunctionData* data = new V8FunctionData(isolate, function_name, handler);
|
|
|
|
return data->CreateExternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
static V8FunctionData* Unwrap(v8::Local<v8::Value> data) {
|
|
|
|
DCHECK(data->IsExternal());
|
|
|
|
return static_cast<V8FunctionData*>(v8::External::Cast(*data)->Value());
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefString function_name() const { return function_name_; }
|
2016-02-05 01:49:19 +01:00
|
|
|
|
2018-02-16 18:56:20 +01:00
|
|
|
CefV8Handler* handler() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!handler_) {
|
2018-02-16 18:56:20 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-02-16 18:56:20 +01:00
|
|
|
return handler_.get();
|
|
|
|
}
|
2016-02-05 01:49:19 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
V8FunctionData(v8::Isolate* isolate,
|
|
|
|
const CefString& function_name,
|
2018-02-16 18:56:20 +01:00
|
|
|
CefRefPtr<CefV8Handler> handler)
|
2017-05-17 11:29:28 +02:00
|
|
|
: isolate_(isolate), function_name_(function_name), handler_(handler) {
|
2016-02-05 01:49:19 +01:00
|
|
|
DCHECK(isolate_);
|
|
|
|
DCHECK(handler_);
|
|
|
|
}
|
|
|
|
|
|
|
|
~V8FunctionData() {
|
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
|
|
|
-static_cast<int>(sizeof(V8FunctionData)));
|
2018-02-16 18:56:20 +01:00
|
|
|
handler_ = nullptr;
|
|
|
|
function_name_ = "FreedFunction";
|
2016-02-05 01:49:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::External> CreateExternal() {
|
|
|
|
v8::Local<v8::External> external = v8::External::New(isolate_, this);
|
|
|
|
|
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
|
|
|
static_cast<int>(sizeof(V8FunctionData)));
|
|
|
|
|
|
|
|
handle_.Reset(isolate_, external);
|
|
|
|
handle_.SetWeak(this, FirstWeakCallback, v8::WeakCallbackType::kParameter);
|
|
|
|
|
|
|
|
return external;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FirstWeakCallback(
|
|
|
|
const v8::WeakCallbackInfo<V8FunctionData>& data) {
|
|
|
|
V8FunctionData* wrapper = data.GetParameter();
|
|
|
|
wrapper->handle_.Reset();
|
|
|
|
data.SetSecondPassCallback(SecondWeakCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SecondWeakCallback(
|
|
|
|
const v8::WeakCallbackInfo<V8FunctionData>& data) {
|
|
|
|
V8FunctionData* wrapper = data.GetParameter();
|
|
|
|
delete wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Isolate* isolate_;
|
|
|
|
CefString function_name_;
|
2018-02-16 18:56:20 +01:00
|
|
|
CefRefPtr<CefV8Handler> handler_;
|
2016-02-05 01:49:19 +01:00
|
|
|
v8::Persistent<v8::External> handle_;
|
|
|
|
};
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Convert a CefString to a V8::String.
|
2017-05-17 11:29:28 +02:00
|
|
|
v8::Local<v8::String> GetV8String(v8::Isolate* isolate, const CefString& str) {
|
2012-04-03 03:34:16 +02:00
|
|
|
#if defined(CEF_STRING_TYPE_UTF16)
|
|
|
|
// Already a UTF16 string.
|
2013-12-17 23:04:35 +01:00
|
|
|
return v8::String::NewFromTwoByte(
|
2019-06-05 16:15:45 +02:00
|
|
|
isolate,
|
|
|
|
reinterpret_cast<uint16_t*>(
|
|
|
|
const_cast<CefString::char_type*>(str.c_str())),
|
|
|
|
v8::NewStringType::kNormal, str.length())
|
|
|
|
.ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
#elif defined(CEF_STRING_TYPE_UTF8)
|
|
|
|
// Already a UTF8 string.
|
2017-05-17 11:29:28 +02:00
|
|
|
return v8::String::NewFromUtf8(isolate, const_cast<char*>(str.c_str()),
|
2019-06-05 16:15:45 +02:00
|
|
|
v8::NewStringType::kNormal, str.length())
|
|
|
|
.ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
#else
|
|
|
|
// Convert the string to UTF8.
|
|
|
|
std::string tmpStr = str;
|
2017-05-17 11:29:28 +02:00
|
|
|
return v8::String::NewFromUtf8(isolate, tmpStr.c_str(),
|
2019-06-05 16:15:45 +02:00
|
|
|
v8::NewStringType::kNormal, tmpStr.length())
|
|
|
|
.ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CEF_STRING_TYPE_UTF16)
|
2023-06-01 16:06:15 +02:00
|
|
|
void v8impl_string_dtor(char16_t* str) {
|
2017-05-17 11:29:28 +02:00
|
|
|
delete[] str;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
#elif defined(CEF_STRING_TYPE_UTF8)
|
|
|
|
void v8impl_string_dtor(char* str) {
|
2017-05-17 11:29:28 +02:00
|
|
|
delete[] str;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Convert a v8::String to CefString.
|
2018-09-04 11:43:21 +02:00
|
|
|
void GetCefString(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::String> str,
|
|
|
|
CefString& out) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (str.IsEmpty()) {
|
2012-07-25 13:50:35 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-07-25 13:50:35 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
#if defined(CEF_STRING_TYPE_WIDE)
|
|
|
|
// Allocate enough space for a worst-case conversion.
|
|
|
|
int len = str->Utf8Length();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (len == 0) {
|
2012-04-25 22:01:10 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
char* buf = new char[len + 1];
|
2018-09-04 11:43:21 +02:00
|
|
|
str->WriteUtf8(isolate, buf, len + 1);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Perform conversion to the wide type.
|
|
|
|
cef_string_t* retws = out.GetWritableStruct();
|
|
|
|
cef_string_utf8_to_wide(buf, len, retws);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
delete[] buf;
|
2012-04-03 03:34:16 +02:00
|
|
|
#else // !defined(CEF_STRING_TYPE_WIDE)
|
|
|
|
#if defined(CEF_STRING_TYPE_UTF16)
|
|
|
|
int len = str->Length();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (len == 0) {
|
2012-04-25 22:01:10 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2023-06-01 16:06:15 +02:00
|
|
|
char16_t* buf = new char16_t[len + 1];
|
2018-09-04 11:43:21 +02:00
|
|
|
str->Write(isolate, reinterpret_cast<uint16_t*>(buf), 0, len + 1);
|
2012-04-03 03:34:16 +02:00
|
|
|
#else
|
|
|
|
// Allocate enough space for a worst-case conversion.
|
|
|
|
int len = str->Utf8Length();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (len == 0) {
|
2012-04-25 22:01:10 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
char* buf = new char[len + 1];
|
2018-09-04 11:43:21 +02:00
|
|
|
str->WriteUtf8(isolate, buf, len + 1);
|
2012-04-03 03:34:16 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Don't perform an extra string copy.
|
|
|
|
out.clear();
|
|
|
|
cef_string_t* retws = out.GetWritableStruct();
|
|
|
|
retws->str = buf;
|
|
|
|
retws->length = len;
|
|
|
|
retws->dtor = v8impl_string_dtor;
|
|
|
|
#endif // !defined(CEF_STRING_TYPE_WIDE)
|
|
|
|
}
|
|
|
|
|
|
|
|
// V8 function callback.
|
2013-07-24 22:15:18 +02:00
|
|
|
void FunctionCallbackImpl(const v8::FunctionCallbackInfo<v8::Value>& info) {
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = info.GetIsolate();
|
2016-01-06 20:20:54 +01:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
V8FunctionData* data = V8FunctionData::Unwrap(info.Data());
|
2018-02-16 18:56:20 +01:00
|
|
|
if (!data->handler()) {
|
|
|
|
// handler has gone away, bail!
|
|
|
|
info.GetReturnValue().SetUndefined();
|
|
|
|
return;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
CefV8ValueList params;
|
2023-01-02 23:59:03 +01:00
|
|
|
for (int i = 0; i < info.Length(); i++) {
|
2016-01-06 20:20:54 +01:00
|
|
|
params.push_back(new CefV8ValueImpl(isolate, context, info[i]));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
CefRefPtr<CefV8Value> object =
|
|
|
|
new CefV8ValueImpl(isolate, context, info.This());
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefV8Value> retval;
|
|
|
|
CefString exception;
|
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
if (data->handler()->Execute(data->function_name(), object, params, retval,
|
|
|
|
exception)) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (!exception.empty()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
info.GetReturnValue().Set(isolate->ThrowException(
|
|
|
|
v8::Exception::Error(GetV8String(isolate, exception))));
|
2013-07-24 22:15:18 +02:00
|
|
|
return;
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
CefV8ValueImpl* rv = static_cast<CefV8ValueImpl*>(retval.get());
|
2013-07-24 22:15:18 +02:00
|
|
|
if (rv && rv->IsValid()) {
|
|
|
|
info.GetReturnValue().Set(rv->GetV8Value(true));
|
|
|
|
return;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 22:15:18 +02:00
|
|
|
info.GetReturnValue().SetUndefined();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// V8 Accessor callbacks
|
2016-01-06 20:20:54 +01:00
|
|
|
void AccessorNameGetterCallbackImpl(
|
|
|
|
v8::Local<v8::Name> property,
|
2013-07-24 22:15:18 +02:00
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = info.GetIsolate();
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Object> obj = info.This();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefV8Accessor> accessorPtr;
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2012-04-03 03:34:16 +02:00
|
|
|
accessorPtr = tracker->GetAccessor();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (accessorPtr.get()) {
|
|
|
|
CefRefPtr<CefV8Value> retval;
|
2016-01-06 20:20:54 +01:00
|
|
|
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(isolate, context, obj);
|
2012-04-03 03:34:16 +02:00
|
|
|
CefString name, exception;
|
2018-09-04 11:43:21 +02:00
|
|
|
GetCefString(isolate, v8::Local<v8::String>::Cast(property), name);
|
2012-04-03 03:34:16 +02:00
|
|
|
if (accessorPtr->Get(name, object, retval, exception)) {
|
|
|
|
if (!exception.empty()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
info.GetReturnValue().Set(isolate->ThrowException(
|
|
|
|
v8::Exception::Error(GetV8String(isolate, exception))));
|
|
|
|
return;
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2017-05-17 11:29:28 +02:00
|
|
|
CefV8ValueImpl* rv = static_cast<CefV8ValueImpl*>(retval.get());
|
|
|
|
if (rv && rv->IsValid()) {
|
|
|
|
info.GetReturnValue().Set(rv->GetV8Value(true));
|
|
|
|
return;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-24 22:15:18 +02:00
|
|
|
return info.GetReturnValue().SetUndefined();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
void AccessorNameSetterCallbackImpl(
|
|
|
|
v8::Local<v8::Name> property,
|
2013-07-24 22:15:18 +02:00
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<void>& info) {
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = info.GetIsolate();
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Object> obj = info.This();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefV8Accessor> accessorPtr;
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2012-04-03 03:34:16 +02:00
|
|
|
accessorPtr = tracker->GetAccessor();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (accessorPtr.get()) {
|
2016-01-06 20:20:54 +01:00
|
|
|
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(isolate, context, obj);
|
|
|
|
CefRefPtr<CefV8Value> cefValue =
|
|
|
|
new CefV8ValueImpl(isolate, context, value);
|
2012-04-03 03:34:16 +02:00
|
|
|
CefString name, exception;
|
2018-09-04 11:43:21 +02:00
|
|
|
GetCefString(isolate, v8::Local<v8::String>::Cast(property), name);
|
2012-04-03 03:34:16 +02:00
|
|
|
accessorPtr->Set(name, object, cefValue, exception);
|
|
|
|
if (!exception.empty()) {
|
2013-12-17 23:04:35 +01:00
|
|
|
isolate->ThrowException(
|
|
|
|
v8::Exception::Error(GetV8String(isolate, exception)));
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 19:23:56 +02:00
|
|
|
// Two helper functions for V8 Interceptor callbacks.
|
2018-09-04 11:43:21 +02:00
|
|
|
CefString PropertyToIndex(v8::Isolate* isolate, v8::Local<v8::Name> property) {
|
2016-10-27 19:23:56 +02:00
|
|
|
CefString name;
|
2018-09-04 11:43:21 +02:00
|
|
|
GetCefString(isolate, property.As<v8::String>(), name);
|
2016-10-27 19:23:56 +02:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
int PropertyToIndex(v8::Isolate* isolate, uint32_t index) {
|
2016-10-27 19:23:56 +02:00
|
|
|
return static_cast<int>(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
// V8 Interceptor callbacks.
|
2018-04-19 17:44:42 +02:00
|
|
|
// T == v8::Local<v8::Name> for named property handlers and
|
2016-10-27 19:23:56 +02:00
|
|
|
// T == uint32_t for indexed property handlers
|
2017-05-17 11:29:28 +02:00
|
|
|
template <typename T>
|
2016-10-27 19:23:56 +02:00
|
|
|
void InterceptorGetterCallbackImpl(
|
|
|
|
T property,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
v8::Isolate* isolate = info.GetIsolate();
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
|
|
|
|
v8::Handle<v8::Object> obj = info.This();
|
|
|
|
CefRefPtr<CefV8Interceptor> interceptorPtr;
|
|
|
|
|
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2016-10-27 19:23:56 +02:00
|
|
|
interceptorPtr = tracker->GetInterceptor();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!interceptorPtr.get()) {
|
2016-10-27 19:23:56 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-10-27 19:23:56 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(isolate, context, obj);
|
|
|
|
CefRefPtr<CefV8Value> retval;
|
|
|
|
CefString exception;
|
2018-09-04 11:43:21 +02:00
|
|
|
interceptorPtr->Get(PropertyToIndex(isolate, property), object, retval,
|
|
|
|
exception);
|
2016-10-27 19:23:56 +02:00
|
|
|
if (!exception.empty()) {
|
|
|
|
info.GetReturnValue().Set(isolate->ThrowException(
|
|
|
|
v8::Exception::Error(GetV8String(isolate, exception))));
|
|
|
|
} else {
|
|
|
|
CefV8ValueImpl* retval_impl = static_cast<CefV8ValueImpl*>(retval.get());
|
|
|
|
if (retval_impl && retval_impl->IsValid()) {
|
|
|
|
info.GetReturnValue().Set(retval_impl->GetV8Value(true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
template <typename T>
|
2016-10-27 19:23:56 +02:00
|
|
|
void InterceptorSetterCallbackImpl(
|
|
|
|
T property,
|
|
|
|
v8::Local<v8::Value> value,
|
|
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
|
|
v8::Isolate* isolate = info.GetIsolate();
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
v8::Handle<v8::Object> obj = info.This();
|
|
|
|
CefRefPtr<CefV8Interceptor> interceptorPtr;
|
|
|
|
|
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2016-10-27 19:23:56 +02:00
|
|
|
interceptorPtr = tracker->GetInterceptor();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-10-27 19:23:56 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!interceptorPtr.get()) {
|
2016-10-27 19:23:56 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-10-27 19:23:56 +02:00
|
|
|
CefRefPtr<CefV8Value> object = new CefV8ValueImpl(isolate, context, obj);
|
|
|
|
CefRefPtr<CefV8Value> cefValue = new CefV8ValueImpl(isolate, context, value);
|
|
|
|
CefString exception;
|
2018-09-04 11:43:21 +02:00
|
|
|
interceptorPtr->Set(PropertyToIndex(isolate, property), object, cefValue,
|
|
|
|
exception);
|
2016-10-27 19:23:56 +02:00
|
|
|
if (!exception.empty()) {
|
|
|
|
isolate->ThrowException(
|
|
|
|
v8::Exception::Error(GetV8String(isolate, exception)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// V8 extension registration.
|
|
|
|
|
|
|
|
class ExtensionWrapper : public v8::Extension {
|
|
|
|
public:
|
|
|
|
ExtensionWrapper(const char* extension_name,
|
|
|
|
const char* javascript_code,
|
|
|
|
CefV8Handler* handler)
|
2017-05-17 11:29:28 +02:00
|
|
|
: v8::Extension(extension_name, javascript_code), handler_(handler) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
v8::Handle<v8::FunctionTemplate> GetNativeFunctionTemplate(
|
2017-05-17 11:29:28 +02:00
|
|
|
v8::Isolate* isolate,
|
|
|
|
v8::Handle<v8::String> name) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!handler_) {
|
2015-04-20 13:11:11 +02:00
|
|
|
return v8::Local<v8::FunctionTemplate>();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
CefString func_name;
|
2018-09-04 11:43:21 +02:00
|
|
|
GetCefString(isolate, name, func_name);
|
2016-02-05 01:49:19 +01:00
|
|
|
|
|
|
|
v8::Local<v8::External> function_data =
|
|
|
|
V8FunctionData::Create(isolate, func_name, handler_);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
return v8::FunctionTemplate::New(isolate, FunctionCallbackImpl,
|
2016-02-05 01:49:19 +01:00
|
|
|
function_data);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefV8Handler* handler_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CefV8ExceptionImpl : public CefV8Exception {
|
|
|
|
public:
|
2016-01-06 20:20:54 +01:00
|
|
|
CefV8ExceptionImpl(v8::Local<v8::Context> context,
|
2024-01-20 23:48:57 +01:00
|
|
|
v8::Local<v8::Message> message) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (message.IsEmpty()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
|
|
GetCefString(isolate, message->Get(), message_);
|
2018-03-20 21:15:08 +01:00
|
|
|
v8::MaybeLocal<v8::String> source_line = message->GetSourceLine(context);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!source_line.IsEmpty()) {
|
2018-09-04 11:43:21 +02:00
|
|
|
GetCefString(isolate, source_line.ToLocalChecked(), source_line_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
if (!message->GetScriptResourceName().IsEmpty()) {
|
|
|
|
GetCefString(
|
|
|
|
isolate,
|
|
|
|
message->GetScriptResourceName()->ToString(context).ToLocalChecked(),
|
|
|
|
script_);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
v8::Maybe<int> line_number = message->GetLineNumber(context);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!line_number.IsNothing()) {
|
2018-03-20 21:15:08 +01:00
|
|
|
line_number_ = line_number.ToChecked();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
start_position_ = message->GetStartPosition();
|
|
|
|
end_position_ = message->GetEndPosition();
|
2016-01-06 20:20:54 +01:00
|
|
|
start_column_ = message->GetStartColumn(context).FromJust();
|
|
|
|
end_column_ = message->GetEndColumn(context).FromJust();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
CefString GetMessage() override { return message_; }
|
|
|
|
CefString GetSourceLine() override { return source_line_; }
|
|
|
|
CefString GetScriptResourceName() override { return script_; }
|
|
|
|
int GetLineNumber() override { return line_number_; }
|
|
|
|
int GetStartPosition() override { return start_position_; }
|
|
|
|
int GetEndPosition() override { return end_position_; }
|
|
|
|
int GetStartColumn() override { return start_column_; }
|
|
|
|
int GetEndColumn() override { return end_column_; }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
CefString message_;
|
|
|
|
CefString source_line_;
|
|
|
|
CefString script_;
|
2024-01-20 23:48:57 +01:00
|
|
|
int line_number_ = 0;
|
|
|
|
int start_position_ = 0;
|
|
|
|
int end_position_ = 0;
|
|
|
|
int start_column_ = 0;
|
|
|
|
int end_column_ = 0;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(CefV8ExceptionImpl);
|
|
|
|
};
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
void MessageListenerCallbackImpl(v8::Handle<v8::Message> message,
|
|
|
|
v8::Handle<v8::Value> data) {
|
2020-06-28 23:05:36 +02:00
|
|
|
CefRefPtr<CefApp> application = CefAppManager::Get()->GetApplication();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!application.get()) {
|
2013-01-03 18:24:24 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-01-03 18:24:24 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefRenderProcessHandler> handler =
|
|
|
|
application->GetRenderProcessHandler();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!handler.get()) {
|
2013-01-03 18:24:24 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-01-03 18:24:24 +01:00
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-01-03 18:24:24 +01:00
|
|
|
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::StackTrace> v8Stack = message->GetStackTrace();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8StackTrace> stackTrace =
|
|
|
|
new CefV8StackTraceImpl(isolate, v8Stack);
|
2013-01-03 18:24:24 +01:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
CefRefPtr<CefV8Exception> exception = new CefV8ExceptionImpl(
|
|
|
|
static_cast<CefV8ContextImpl*>(context.get())->GetV8Context(), message);
|
2013-01-03 18:24:24 +01:00
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
CefRefPtr<CefBrowser> browser = context->GetBrowser();
|
|
|
|
if (browser) {
|
|
|
|
handler->OnUncaughtException(browser, context->GetFrame(), context,
|
|
|
|
exception, stackTrace);
|
|
|
|
}
|
2013-01-03 18:24:24 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// Global functions.
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
void CefV8IsolateCreated() {
|
2023-04-04 20:00:13 +02:00
|
|
|
new CefV8IsolateManager();
|
2013-01-03 18:24:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8IsolateDestroyed() {
|
2023-04-04 20:00:13 +02:00
|
|
|
auto* isolate_manager = CefV8IsolateManager::Get();
|
|
|
|
isolate_manager->Destroy();
|
2013-01-03 18:24:24 +01:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
void CefV8ReleaseContext(v8::Local<v8::Context> context) {
|
2023-04-04 20:00:13 +02:00
|
|
|
CefV8IsolateManager::Get()->ReleaseContext(context);
|
2013-01-03 18:24:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8SetUncaughtExceptionStackSize(int stack_size) {
|
2023-04-04 20:00:13 +02:00
|
|
|
CefV8IsolateManager::Get()->SetUncaughtExceptionStackSize(stack_size);
|
2013-01-03 18:24:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8SetWorkerAttributes(int worker_id, const GURL& worker_url) {
|
2023-04-04 20:00:13 +02:00
|
|
|
CefV8IsolateManager::Get()->SetWorkerAttributes(worker_id, worker_url);
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefRegisterExtension(const CefString& extension_name,
|
|
|
|
const CefString& javascript_code,
|
|
|
|
CefRefPtr<CefV8Handler> handler) {
|
|
|
|
// Verify that this method was called on the correct thread.
|
|
|
|
CEF_REQUIRE_RT_RETURN(false);
|
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
auto* isolate_manager = CefV8IsolateManager::Get();
|
2013-12-17 23:04:35 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
V8TrackString* name = new V8TrackString(extension_name);
|
2013-12-17 23:04:35 +01:00
|
|
|
isolate_manager->AddGlobalTrackObject(name);
|
2012-04-03 03:34:16 +02:00
|
|
|
V8TrackString* code = new V8TrackString(javascript_code);
|
2013-12-17 23:04:35 +01:00
|
|
|
isolate_manager->AddGlobalTrackObject(code);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-09-27 01:48:19 +02:00
|
|
|
if (handler.get()) {
|
2013-12-17 23:04:35 +01:00
|
|
|
// The reference will be released when the process exits.
|
|
|
|
V8TrackObject* object = new V8TrackObject(isolate_manager->isolate());
|
|
|
|
object->SetHandler(handler);
|
|
|
|
isolate_manager->AddGlobalTrackObject(object);
|
|
|
|
}
|
|
|
|
|
2019-02-21 01:42:36 +01:00
|
|
|
std::unique_ptr<v8::Extension> wrapper(new ExtensionWrapper(
|
|
|
|
name->GetString(), code->GetString(), handler.get()));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2022-06-17 15:28:55 +02:00
|
|
|
blink::WebScriptController::RegisterExtension(std::move(wrapper));
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-30 22:16:59 +01:00
|
|
|
// Helper macros
|
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
#define CEF_V8_HAS_ISOLATE() (!!CefV8IsolateManager::Get())
|
2023-05-08 17:07:57 +02:00
|
|
|
#define CEF_V8_REQUIRE_ISOLATE_RETURN(var) \
|
|
|
|
if (!CEF_V8_HAS_ISOLATE()) { \
|
|
|
|
DCHECK(false) << "V8 isolate is not valid"; \
|
|
|
|
return var; \
|
2012-12-30 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
2013-06-27 00:33:44 +02:00
|
|
|
#define CEF_V8_CURRENTLY_ON_MLT() \
|
2017-05-17 11:29:28 +02:00
|
|
|
(!handle_.get() || handle_->BelongsToCurrentThread())
|
2023-05-08 17:07:57 +02:00
|
|
|
#define CEF_V8_REQUIRE_MLT_RETURN(var) \
|
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(var); \
|
|
|
|
if (!CEF_V8_CURRENTLY_ON_MLT()) { \
|
|
|
|
DCHECK(false) << "called on incorrect thread"; \
|
|
|
|
return var; \
|
2012-12-30 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
2013-06-27 00:33:44 +02:00
|
|
|
#define CEF_V8_HANDLE_IS_VALID() (handle_.get() && handle_->IsValid())
|
|
|
|
#define CEF_V8_REQUIRE_VALID_HANDLE_RETURN(ret) \
|
2017-05-17 11:29:28 +02:00
|
|
|
CEF_V8_REQUIRE_MLT_RETURN(ret); \
|
|
|
|
if (!CEF_V8_HANDLE_IS_VALID()) { \
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 handle is not valid"; \
|
2017-05-17 11:29:28 +02:00
|
|
|
return ret; \
|
2012-12-30 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
#define CEF_V8_IS_VALID() \
|
|
|
|
(CEF_V8_HAS_ISOLATE() && CEF_V8_CURRENTLY_ON_MLT() && \
|
2012-12-30 22:16:59 +01:00
|
|
|
CEF_V8_HANDLE_IS_VALID())
|
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
#define CEF_V8_REQUIRE_OBJECT_RETURN(ret) \
|
|
|
|
CEF_V8_REQUIRE_VALID_HANDLE_RETURN(ret); \
|
|
|
|
if (type_ != TYPE_OBJECT) { \
|
|
|
|
DCHECK(false) << "V8 value is not an object"; \
|
|
|
|
return ret; \
|
2012-12-30 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
// CefV8HandleBase
|
|
|
|
|
2012-12-30 22:16:59 +01:00
|
|
|
CefV8HandleBase::~CefV8HandleBase() {
|
|
|
|
DCHECK(BelongsToCurrentThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8HandleBase::BelongsToCurrentThread() const {
|
2017-09-06 23:40:58 +02:00
|
|
|
return task_runner_->RunsTasksInCurrentSequence();
|
2012-12-30 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
CefV8HandleBase::CefV8HandleBase(v8::Isolate* isolate,
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Context> context)
|
2013-12-17 23:04:35 +01:00
|
|
|
: isolate_(isolate) {
|
|
|
|
DCHECK(isolate_);
|
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
CefV8IsolateManager* manager = CefV8IsolateManager::Get();
|
2013-01-03 18:24:24 +01:00
|
|
|
DCHECK(manager);
|
2013-12-17 23:04:35 +01:00
|
|
|
DCHECK_EQ(isolate_, manager->isolate());
|
2013-03-12 21:23:24 +01:00
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
task_runner_ = manager->task_runner();
|
|
|
|
context_state_ = manager->GetContextState(context);
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2012-07-25 13:50:35 +02:00
|
|
|
// CefV8Context
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Context> CefV8Context::GetCurrentContext() {
|
|
|
|
CefRefPtr<CefV8Context> context;
|
2012-12-30 22:16:59 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(context);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
if (isolate->InContext()) {
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
context = new CefV8ContextImpl(isolate, isolate->GetCurrentContext());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Context> CefV8Context::GetEnteredContext() {
|
|
|
|
CefRefPtr<CefV8Context> context;
|
2012-12-30 22:16:59 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(context);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
if (isolate->InContext()) {
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2019-01-17 10:56:52 +01:00
|
|
|
context =
|
|
|
|
new CefV8ContextImpl(isolate, isolate->GetEnteredOrMicrotaskContext());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool CefV8Context::InContext() {
|
2012-12-30 22:16:59 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
return isolate->InContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-07-25 13:50:35 +02:00
|
|
|
// CefV8ContextImpl
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
CefV8ContextImpl::CefV8ContextImpl(v8::Isolate* isolate,
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Context> context)
|
2023-01-03 00:34:43 +01:00
|
|
|
: handle_(new Handle(isolate, context, context)),
|
|
|
|
microtask_queue_(blink_glue::GetMicrotaskQueue(context)) {}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefV8ContextImpl::~CefV8ContextImpl() {
|
|
|
|
DLOG_ASSERT(0 == enter_count_);
|
|
|
|
}
|
|
|
|
|
2013-01-03 18:24:24 +01:00
|
|
|
CefRefPtr<CefTaskRunner> CefV8ContextImpl::GetTaskRunner() {
|
|
|
|
return new CefTaskRunnerImpl(handle_->task_runner());
|
|
|
|
}
|
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
bool CefV8ContextImpl::IsValid() {
|
2012-12-30 22:16:59 +01:00
|
|
|
return CEF_V8_IS_VALID();
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefBrowser> CefV8ContextImpl::GetBrowser() {
|
|
|
|
CefRefPtr<CefBrowser> browser;
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_VALID_HANDLE_RETURN(browser);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
blink::WebLocalFrame* webframe = GetWebFrame();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (webframe) {
|
2017-04-20 21:28:17 +02:00
|
|
|
browser = CefBrowserImpl::GetBrowserForMainFrame(webframe->Top());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return browser;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefFrame> CefV8ContextImpl::GetFrame() {
|
|
|
|
CefRefPtr<CefFrame> frame;
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_VALID_HANDLE_RETURN(frame);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
blink::WebLocalFrame* webframe = GetWebFrame();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (webframe) {
|
|
|
|
CefRefPtr<CefBrowserImpl> browser =
|
2017-04-20 21:28:17 +02:00
|
|
|
CefBrowserImpl::GetBrowserForMainFrame(webframe->Top());
|
2017-12-07 22:44:24 +01:00
|
|
|
if (browser) {
|
2024-01-26 03:12:43 +01:00
|
|
|
frame = browser->GetWebFrameImpl(webframe).get();
|
2017-12-07 22:44:24 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> CefV8ContextImpl::GetGlobal() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_VALID_HANDLE_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (blink_glue::IsScriptForbidden()) {
|
2016-02-05 01:49:19 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-02-05 01:49:19 +01:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Context> context = GetV8Context();
|
2013-06-27 00:33:44 +02:00
|
|
|
v8::Context::Scope context_scope(context);
|
2016-01-06 20:20:54 +01:00
|
|
|
return new CefV8ValueImpl(isolate, context, context->Global());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ContextImpl::Enter() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_VALID_HANDLE_RETURN(false);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (blink_glue::IsScriptForbidden()) {
|
2016-02-05 01:49:19 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-02-05 01:49:19 +01:00
|
|
|
|
2014-04-30 19:14:40 +02:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2012-10-29 22:46:02 +01:00
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
if (!microtasks_scope_) {
|
|
|
|
// Increment the MicrotasksScope recursion level.
|
2024-01-20 23:48:57 +01:00
|
|
|
microtasks_scope_ = std::make_unique<v8::MicrotasksScope>(
|
|
|
|
isolate, microtask_queue_, v8::MicrotasksScope::kRunMicrotasks);
|
2016-03-16 03:55:59 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
++enter_count_;
|
2016-03-16 03:55:59 +01:00
|
|
|
handle_->GetNewV8Handle()->Enter();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ContextImpl::Exit() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_VALID_HANDLE_RETURN(false);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (blink_glue::IsScriptForbidden()) {
|
2016-02-05 01:49:19 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-02-05 01:49:19 +01:00
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
if (enter_count_ <= 0) {
|
|
|
|
LOG(ERROR) << "Call to CefV8Context::Exit() without matching call to "
|
|
|
|
"CefV8Context::Enter()";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-16 02:25:38 +02:00
|
|
|
v8::HandleScope handle_scope(handle_->isolate());
|
2012-10-29 22:46:02 +01:00
|
|
|
|
2013-06-27 00:33:44 +02:00
|
|
|
handle_->GetNewV8Handle()->Exit();
|
2016-03-16 03:55:59 +01:00
|
|
|
|
|
|
|
if (--enter_count_ == 0) {
|
|
|
|
// Decrement the MicrotasksScope recursion level.
|
|
|
|
microtasks_scope_.reset(nullptr);
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ContextImpl::IsSame(CefRefPtr<CefV8Context> that) {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_VALID_HANDLE_RETURN(false);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefV8ContextImpl* impl = static_cast<CefV8ContextImpl*>(that.get());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!impl || !impl->IsValid()) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-06-27 00:33:44 +02:00
|
|
|
return (handle_->GetPersistentV8Handle() ==
|
|
|
|
impl->handle_->GetPersistentV8Handle());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ContextImpl::Eval(const CefString& code,
|
2016-10-27 18:34:19 +02:00
|
|
|
const CefString& script_url,
|
|
|
|
int start_line,
|
2012-04-03 03:34:16 +02:00
|
|
|
CefRefPtr<CefV8Value>& retval,
|
|
|
|
CefRefPtr<CefV8Exception>& exception) {
|
2020-01-15 14:36:24 +01:00
|
|
|
retval = nullptr;
|
|
|
|
exception = nullptr;
|
2016-10-27 18:34:19 +02:00
|
|
|
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_VALID_HANDLE_RETURN(false);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (blink_glue::IsScriptForbidden()) {
|
2016-02-05 01:49:19 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-02-05 01:49:19 +01:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if (code.empty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid input parameter";
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
v8::Local<v8::Context> context = GetV8Context();
|
2013-01-03 18:24:24 +01:00
|
|
|
v8::Context::Scope context_scope(context);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
const blink::WebString& source =
|
|
|
|
blink::WebString::FromUTF16(code.ToString16());
|
|
|
|
const blink::WebString& source_url =
|
|
|
|
blink::WebString::FromUTF16(script_url.ToString16());
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
|
|
|
|
2020-10-08 21:54:42 +02:00
|
|
|
v8::Local<v8::Value> func_rv = blink_glue::ExecuteV8ScriptAndReturnValue(
|
2021-03-04 23:36:57 +01:00
|
|
|
source, source_url, start_line, context, try_catch);
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
if (try_catch.HasCaught()) {
|
2016-01-06 20:20:54 +01:00
|
|
|
exception = new CefV8ExceptionImpl(context, try_catch.Message());
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2012-04-24 20:01:48 +02:00
|
|
|
} else if (!func_rv.IsEmpty()) {
|
2020-10-08 21:54:42 +02:00
|
|
|
retval = new CefV8ValueImpl(isolate, context, func_rv);
|
2016-10-27 18:34:19 +02:00
|
|
|
return true;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2016-10-27 18:34:19 +02:00
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2016-10-27 18:34:19 +02:00
|
|
|
return false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Context> CefV8ContextImpl::GetV8Context() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return handle_->GetNewV8Handle();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
blink::WebLocalFrame* CefV8ContextImpl::GetWebFrame() {
|
2013-01-03 18:24:24 +01:00
|
|
|
CEF_REQUIRE_RT();
|
2016-02-05 01:49:19 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (blink_glue::IsScriptForbidden()) {
|
2016-02-05 01:49:19 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-02-05 01:49:19 +01:00
|
|
|
|
2013-10-16 02:25:38 +02:00
|
|
|
v8::HandleScope handle_scope(handle_->isolate());
|
2016-02-05 01:49:19 +01:00
|
|
|
v8::Local<v8::Context> context = GetV8Context();
|
|
|
|
v8::Context::Scope context_scope(context);
|
2017-04-20 21:28:17 +02:00
|
|
|
return blink::WebLocalFrame::FrameForContext(context);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-07-25 13:50:35 +02:00
|
|
|
// CefV8ValueImpl::Handle
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2014-05-29 23:25:19 +02:00
|
|
|
CefV8ValueImpl::Handle::Handle(v8::Isolate* isolate,
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Context> context,
|
2014-05-29 23:25:19 +02:00
|
|
|
handleType v,
|
|
|
|
CefTrackNode* tracker)
|
|
|
|
: CefV8HandleBase(isolate, context),
|
|
|
|
handle_(isolate, v),
|
2024-01-20 23:48:57 +01:00
|
|
|
tracker_(tracker) {}
|
2014-05-29 23:25:19 +02:00
|
|
|
|
2012-07-25 13:50:35 +02:00
|
|
|
CefV8ValueImpl::Handle::~Handle() {
|
2014-05-29 23:25:19 +02:00
|
|
|
DCHECK(BelongsToCurrentThread());
|
|
|
|
|
|
|
|
if (tracker_) {
|
|
|
|
if (is_set_weak_) {
|
|
|
|
if (context_state_.get()) {
|
|
|
|
// If the associated context is still valid then delete |tracker_|.
|
|
|
|
// Otherwise, |tracker_| will already have been deleted.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (context_state_->IsValid()) {
|
2014-05-29 23:25:19 +02:00
|
|
|
context_state_->DeleteTrackObject(tracker_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-05-29 23:25:19 +02:00
|
|
|
} else {
|
2023-04-04 20:00:13 +02:00
|
|
|
CefV8IsolateManager::Get()->DeleteGlobalTrackObject(tracker_);
|
2014-05-29 23:25:19 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delete tracker_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
if (is_set_weak_) {
|
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
|
|
|
-static_cast<int>(sizeof(Handle)));
|
|
|
|
} else {
|
|
|
|
// SetWeak was not called so reset now.
|
|
|
|
handle_.Reset();
|
|
|
|
}
|
2014-05-29 23:25:19 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefV8ValueImpl::Handle::handleType CefV8ValueImpl::Handle::GetNewV8Handle(
|
|
|
|
bool should_persist) {
|
2014-05-29 23:25:19 +02:00
|
|
|
DCHECK(IsValid());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (should_persist && !should_persist_) {
|
2014-05-29 23:25:19 +02:00
|
|
|
should_persist_ = true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-05-29 23:25:19 +02:00
|
|
|
return handleType::New(isolate(), handle_);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefV8ValueImpl::Handle::persistentType&
|
|
|
|
CefV8ValueImpl::Handle::GetPersistentV8Handle() {
|
|
|
|
return handle_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8ValueImpl::Handle::SetWeakIfNecessary() {
|
|
|
|
if (!BelongsToCurrentThread()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
task_runner()->PostTask(
|
|
|
|
FROM_HERE,
|
2021-06-04 03:34:56 +02:00
|
|
|
base::BindOnce(&CefV8ValueImpl::Handle::SetWeakIfNecessary, this));
|
2014-05-29 23:25:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Persist the handle (call SetWeak) if:
|
2013-03-12 21:23:24 +01:00
|
|
|
// A. The handle has been passed into a V8 function or used as a return value
|
2012-10-30 21:49:43 +01:00
|
|
|
// from a V8 callback, and
|
2013-03-12 21:23:24 +01:00
|
|
|
// B. The associated context, if any, is still valid.
|
|
|
|
if (should_persist_ && (!context_state_.get() || context_state_->IsValid())) {
|
2014-05-29 23:25:19 +02:00
|
|
|
is_set_weak_ = true;
|
|
|
|
|
|
|
|
if (tracker_) {
|
|
|
|
if (context_state_.get()) {
|
|
|
|
// |tracker_| will be deleted when:
|
|
|
|
// A. The associated context is released, or
|
2016-02-05 01:49:19 +01:00
|
|
|
// B. SecondWeakCallback is called for the weak handle.
|
2014-05-29 23:25:19 +02:00
|
|
|
DCHECK(context_state_->IsValid());
|
|
|
|
context_state_->AddTrackObject(tracker_);
|
|
|
|
} else {
|
|
|
|
// |tracker_| will be deleted when:
|
|
|
|
// A. The process shuts down, or
|
2016-02-05 01:49:19 +01:00
|
|
|
// B. SecondWeakCallback is called for the weak handle.
|
2023-04-04 20:00:13 +02:00
|
|
|
CefV8IsolateManager::Get()->AddGlobalTrackObject(tracker_);
|
2014-05-29 23:25:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isolate_->AdjustAmountOfExternalAllocatedMemory(
|
|
|
|
static_cast<int>(sizeof(Handle)));
|
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
// The added reference will be released in SecondWeakCallback.
|
2014-05-29 23:25:19 +02:00
|
|
|
AddRef();
|
2016-02-05 01:49:19 +01:00
|
|
|
handle_.SetWeak(this, FirstWeakCallback, v8::WeakCallbackType::kParameter);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
2014-05-29 23:25:19 +02:00
|
|
|
}
|
2014-01-02 23:41:11 +01:00
|
|
|
|
2014-05-29 23:25:19 +02:00
|
|
|
// static
|
2016-02-05 01:49:19 +01:00
|
|
|
void CefV8ValueImpl::Handle::FirstWeakCallback(
|
2016-01-06 20:20:54 +01:00
|
|
|
const v8::WeakCallbackInfo<Handle>& data) {
|
2016-02-05 01:49:19 +01:00
|
|
|
Handle* wrapper = data.GetParameter();
|
|
|
|
wrapper->handle_.Reset();
|
|
|
|
data.SetSecondPassCallback(SecondWeakCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void CefV8ValueImpl::Handle::SecondWeakCallback(
|
|
|
|
const v8::WeakCallbackInfo<Handle>& data) {
|
|
|
|
Handle* wrapper = data.GetParameter();
|
|
|
|
wrapper->Release();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CefV8Value
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateUndefined() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitUndefined();
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateNull() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitNull();
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateBool(bool value) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitBool(value);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2023-06-01 16:06:15 +02:00
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateInt(int32_t value) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitInt(value);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2023-06-01 16:06:15 +02:00
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateUInt(uint32_t value) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitUInt(value);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateDouble(double value) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitDouble(value);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2022-05-31 22:28:43 +02:00
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateDate(CefBaseTime value) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitDate(value);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateString(const CefString& value) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
CefString str(value);
|
|
|
|
impl->InitString(str);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateObject(
|
2016-10-27 19:23:56 +02:00
|
|
|
CefRefPtr<CefV8Accessor> accessor,
|
|
|
|
CefRefPtr<CefV8Interceptor> interceptor) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-10-27 19:23:56 +02:00
|
|
|
// Create the new V8 object. If an interceptor is passed, create object from
|
|
|
|
// template and set property handlers.
|
|
|
|
v8::Local<v8::Object> obj;
|
|
|
|
if (interceptor.get()) {
|
|
|
|
v8::Local<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(isolate);
|
2018-04-19 17:44:42 +02:00
|
|
|
tmpl->SetHandler(v8::NamedPropertyHandlerConfiguration(
|
|
|
|
InterceptorGetterCallbackImpl<v8::Local<v8::Name>>,
|
|
|
|
InterceptorSetterCallbackImpl<v8::Local<v8::Name>>, nullptr, nullptr,
|
|
|
|
nullptr, v8::Local<v8::Value>(),
|
|
|
|
v8::PropertyHandlerFlags::kOnlyInterceptStrings));
|
2016-10-27 19:23:56 +02:00
|
|
|
|
|
|
|
tmpl->SetIndexedPropertyHandler(InterceptorGetterCallbackImpl<uint32_t>,
|
|
|
|
InterceptorSetterCallbackImpl<uint32_t>);
|
2018-12-26 16:12:11 +01:00
|
|
|
|
|
|
|
v8::MaybeLocal<v8::Object> maybe_object = tmpl->NewInstance(context);
|
|
|
|
if (!maybe_object.ToLocal<v8::Object>(&obj)) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Failed to create V8 Object with interceptor";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2018-12-26 16:12:11 +01:00
|
|
|
}
|
2016-10-27 19:23:56 +02:00
|
|
|
} else {
|
|
|
|
obj = v8::Object::New(isolate);
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Create a tracker object that will cause the user data and/or accessor
|
2016-10-27 19:23:56 +02:00
|
|
|
// and/or interceptor reference to be released when the V8 object is
|
|
|
|
// destroyed.
|
2013-12-17 23:04:35 +01:00
|
|
|
V8TrackObject* tracker = new V8TrackObject(isolate);
|
2012-04-03 03:34:16 +02:00
|
|
|
tracker->SetAccessor(accessor);
|
2016-10-27 19:23:56 +02:00
|
|
|
tracker->SetInterceptor(interceptor);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Attach the tracker object.
|
2015-12-09 17:10:16 +01:00
|
|
|
tracker->AttachTo(context, obj);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitObject(obj, tracker);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateArray(int length) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a tracker object that will cause the user data reference to be
|
|
|
|
// released when the V8 object is destroyed.
|
2013-12-17 23:04:35 +01:00
|
|
|
V8TrackObject* tracker = new V8TrackObject(isolate);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Create the new V8 array.
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Local<v8::Array> arr = v8::Array::New(isolate, length);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Attach the tracker object.
|
2015-12-09 17:10:16 +01:00
|
|
|
tracker->AttachTo(context, arr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitObject(arr, tracker);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 21:37:33 +02:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateArrayBuffer(
|
|
|
|
void* buffer,
|
|
|
|
size_t length,
|
|
|
|
CefRefPtr<CefV8ArrayBufferReleaseCallback> release_callback) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2018-04-10 21:37:33 +02:00
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2018-04-10 21:37:33 +02:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2018-04-10 21:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a tracker object that will cause the user data reference to be
|
|
|
|
// released when the V8 object is destroyed.
|
|
|
|
V8TrackArrayBuffer* tracker =
|
2021-03-23 20:58:17 +01:00
|
|
|
new V8TrackArrayBuffer(isolate, release_callback);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (release_callback) {
|
2021-03-23 20:58:17 +01:00
|
|
|
release_callback->AddRef();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-03-12 18:26:52 +01:00
|
|
|
|
|
|
|
auto deleter = [](void* data, size_t length, void* deleter_data) {
|
2021-03-23 20:58:17 +01:00
|
|
|
auto* release_callback =
|
|
|
|
reinterpret_cast<CefV8ArrayBufferReleaseCallback*>(deleter_data);
|
|
|
|
if (release_callback) {
|
|
|
|
release_callback->ReleaseBuffer(data);
|
|
|
|
release_callback->Release();
|
2021-03-12 18:26:52 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-23 20:58:17 +01:00
|
|
|
std::unique_ptr<v8::BackingStore> backing = v8::ArrayBuffer::NewBackingStore(
|
|
|
|
buffer, length, deleter, release_callback.get());
|
2021-03-12 18:26:52 +01:00
|
|
|
v8::Local<v8::ArrayBuffer> ab =
|
|
|
|
v8::ArrayBuffer::New(isolate, std::move(backing));
|
2018-04-10 21:37:33 +02:00
|
|
|
|
|
|
|
// Attach the tracker object.
|
|
|
|
tracker->AttachTo(context, ab);
|
|
|
|
|
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
|
|
|
impl->InitObject(ab, tracker);
|
|
|
|
return impl.get();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreateFunction(
|
|
|
|
const CefString& name,
|
|
|
|
CefRefPtr<CefV8Handler> handler) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (!handler.get()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid parameter";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
v8::Local<v8::External> function_data =
|
2018-02-16 18:56:20 +01:00
|
|
|
V8FunctionData::Create(isolate, name, handler);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-02-05 01:49:19 +01:00
|
|
|
// Create a new V8 function template.
|
|
|
|
v8::Local<v8::FunctionTemplate> tmpl =
|
2017-05-17 11:29:28 +02:00
|
|
|
v8::FunctionTemplate::New(isolate, FunctionCallbackImpl, function_data);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Retrieve the function object and set the name.
|
2018-12-26 16:12:11 +01:00
|
|
|
v8::MaybeLocal<v8::Function> maybe_func = tmpl->GetFunction(context);
|
|
|
|
v8::Local<v8::Function> func;
|
|
|
|
if (!maybe_func.ToLocal(&func)) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "failed to create V8 function";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
func->SetName(GetV8String(isolate, name));
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Create a tracker object that will cause the user data and/or handler
|
|
|
|
// reference to be released when the V8 object is destroyed.
|
2013-12-17 23:04:35 +01:00
|
|
|
V8TrackObject* tracker = new V8TrackObject(isolate);
|
2012-04-03 03:34:16 +02:00
|
|
|
tracker->SetHandler(handler);
|
|
|
|
|
|
|
|
// Attach the tracker object.
|
2015-12-09 17:10:16 +01:00
|
|
|
tracker->AttachTo(context, func);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Create the CefV8ValueImpl and provide a tracker object that will cause
|
|
|
|
// the handler reference to be released when the V8 object is destroyed.
|
2013-12-17 23:04:35 +01:00
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
2013-06-27 00:33:44 +02:00
|
|
|
impl->InitObject(func, tracker);
|
|
|
|
return impl.get();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-11 20:54:32 +02:00
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8Value> CefV8Value::CreatePromise() {
|
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2022-10-11 20:54:32 +02:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2022-10-11 20:54:32 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Promise::Resolver> promise_resolver =
|
|
|
|
v8::Promise::Resolver::New(context).ToLocalChecked();
|
|
|
|
|
|
|
|
// Create a tracker object that will cause the user data reference to be
|
|
|
|
// released when the V8 object is destroyed.
|
|
|
|
V8TrackObject* tracker = new V8TrackObject(isolate);
|
|
|
|
|
|
|
|
// Attach the tracker object.
|
|
|
|
tracker->AttachTo(context, promise_resolver);
|
|
|
|
|
|
|
|
CefRefPtr<CefV8ValueImpl> impl = new CefV8ValueImpl(isolate);
|
|
|
|
impl->InitObject(promise_resolver, tracker);
|
|
|
|
return impl.get();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// CefV8ValueImpl
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
CefV8ValueImpl::CefV8ValueImpl(v8::Isolate* isolate)
|
2017-05-17 11:29:28 +02:00
|
|
|
: isolate_(isolate), type_(TYPE_INVALID), rethrow_exceptions_(false) {
|
2013-12-17 23:04:35 +01:00
|
|
|
DCHECK(isolate_);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
CefV8ValueImpl::CefV8ValueImpl(v8::Isolate* isolate,
|
2016-01-06 20:20:54 +01:00
|
|
|
v8::Local<v8::Context> context,
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value)
|
2017-05-17 11:29:28 +02:00
|
|
|
: isolate_(isolate), type_(TYPE_INVALID), rethrow_exceptions_(false) {
|
2013-12-17 23:04:35 +01:00
|
|
|
DCHECK(isolate_);
|
2016-01-06 20:20:54 +01:00
|
|
|
InitFromV8Value(context, value);
|
2013-06-27 00:33:44 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefV8ValueImpl::~CefV8ValueImpl() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == TYPE_STRING) {
|
2013-06-27 00:33:44 +02:00
|
|
|
cef_string_clear(&string_value_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (handle_.get()) {
|
2014-05-29 23:25:19 +02:00
|
|
|
handle_->SetWeakIfNecessary();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-06-27 00:33:44 +02:00
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
void CefV8ValueImpl::InitFromV8Value(v8::Local<v8::Context> context,
|
|
|
|
v8::Local<v8::Value> value) {
|
2013-06-27 00:33:44 +02:00
|
|
|
if (value->IsUndefined()) {
|
|
|
|
InitUndefined();
|
|
|
|
} else if (value->IsNull()) {
|
|
|
|
InitNull();
|
|
|
|
} else if (value->IsTrue()) {
|
|
|
|
InitBool(true);
|
|
|
|
} else if (value->IsFalse()) {
|
|
|
|
InitBool(false);
|
|
|
|
} else if (value->IsBoolean()) {
|
2019-06-05 16:15:45 +02:00
|
|
|
InitBool(value->ToBoolean(context->GetIsolate())->Value());
|
2013-06-27 00:33:44 +02:00
|
|
|
} else if (value->IsInt32()) {
|
2016-01-06 20:20:54 +01:00
|
|
|
InitInt(value->ToInt32(context).ToLocalChecked()->Value());
|
2013-06-27 00:33:44 +02:00
|
|
|
} else if (value->IsUint32()) {
|
2016-01-06 20:20:54 +01:00
|
|
|
InitUInt(value->ToUint32(context).ToLocalChecked()->Value());
|
2013-06-27 00:33:44 +02:00
|
|
|
} else if (value->IsNumber()) {
|
2016-01-06 20:20:54 +01:00
|
|
|
InitDouble(value->ToNumber(context).ToLocalChecked()->Value());
|
2013-06-27 00:33:44 +02:00
|
|
|
} else if (value->IsDate()) {
|
|
|
|
// Convert from milliseconds to seconds.
|
2023-11-21 20:17:55 +01:00
|
|
|
InitDate(base::Time::FromMillisecondsSinceUnixEpoch(
|
2022-05-31 22:28:43 +02:00
|
|
|
value->ToNumber(context).ToLocalChecked()->Value()));
|
2013-06-27 00:33:44 +02:00
|
|
|
} else if (value->IsString()) {
|
|
|
|
CefString rv;
|
2018-09-04 11:43:21 +02:00
|
|
|
GetCefString(context->GetIsolate(),
|
|
|
|
value->ToString(context).ToLocalChecked(), rv);
|
2013-06-27 00:33:44 +02:00
|
|
|
InitString(rv);
|
|
|
|
} else if (value->IsObject()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
InitObject(value, nullptr);
|
2013-06-27 00:33:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8ValueImpl::InitUndefined() {
|
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_UNDEFINED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8ValueImpl::InitNull() {
|
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8ValueImpl::InitBool(bool value) {
|
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_BOOL;
|
|
|
|
bool_value_ = value;
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
void CefV8ValueImpl::InitInt(int32_t value) {
|
2013-06-27 00:33:44 +02:00
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_INT;
|
|
|
|
int_value_ = value;
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
void CefV8ValueImpl::InitUInt(uint32_t value) {
|
2013-06-27 00:33:44 +02:00
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_UINT;
|
|
|
|
uint_value_ = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8ValueImpl::InitDouble(double value) {
|
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_DOUBLE;
|
|
|
|
double_value_ = value;
|
|
|
|
}
|
|
|
|
|
2022-05-31 22:28:43 +02:00
|
|
|
void CefV8ValueImpl::InitDate(CefBaseTime value) {
|
2013-06-27 00:33:44 +02:00
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_DATE;
|
|
|
|
date_value_ = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefV8ValueImpl::InitString(CefString& value) {
|
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_STRING;
|
|
|
|
// Take ownership of the underling string value.
|
|
|
|
const cef_string_t* str = value.GetStruct();
|
|
|
|
if (str) {
|
|
|
|
string_value_ = *str;
|
2013-07-18 20:09:09 +02:00
|
|
|
cef_string_t* writable_struct = value.GetWritableStruct();
|
2020-01-15 14:36:24 +01:00
|
|
|
writable_struct->str = nullptr;
|
2013-07-18 20:09:09 +02:00
|
|
|
writable_struct->length = 0;
|
2013-06-27 00:33:44 +02:00
|
|
|
} else {
|
2020-01-15 14:36:24 +01:00
|
|
|
string_value_.str = nullptr;
|
2013-07-18 20:09:09 +02:00
|
|
|
string_value_.length = 0;
|
2013-06-27 00:33:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefV8ValueImpl::InitObject(v8::Local<v8::Value> value,
|
|
|
|
CefTrackNode* tracker) {
|
2013-06-27 00:33:44 +02:00
|
|
|
DCHECK_EQ(type_, TYPE_INVALID);
|
|
|
|
type_ = TYPE_OBJECT;
|
2015-04-20 13:11:11 +02:00
|
|
|
handle_ = new Handle(isolate_, v8::Local<v8::Context>(), value, tracker);
|
2013-06-27 00:33:44 +02:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> CefV8ValueImpl::GetV8Value(bool should_persist) {
|
2013-06-27 00:33:44 +02:00
|
|
|
switch (type_) {
|
|
|
|
case TYPE_UNDEFINED:
|
2013-12-17 23:04:35 +01:00
|
|
|
return v8::Undefined(isolate_);
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_NULL:
|
2013-12-17 23:04:35 +01:00
|
|
|
return v8::Null(isolate_);
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_BOOL:
|
2013-12-17 23:04:35 +01:00
|
|
|
return v8::Boolean::New(isolate_, bool_value_);
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_INT:
|
2013-12-17 23:04:35 +01:00
|
|
|
return v8::Int32::New(isolate_, int_value_);
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_UINT:
|
2022-04-13 21:07:31 +02:00
|
|
|
return v8::Uint32::NewFromUnsigned(isolate_, uint_value_);
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_DOUBLE:
|
2013-12-17 23:04:35 +01:00
|
|
|
return v8::Number::New(isolate_, double_value_);
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_DATE:
|
|
|
|
// Convert from seconds to milliseconds.
|
2018-10-02 14:14:11 +02:00
|
|
|
return v8::Date::New(isolate_->GetCurrentContext(),
|
2022-05-31 22:28:43 +02:00
|
|
|
static_cast<base::Time>(CefBaseTime(date_value_))
|
2023-11-21 20:17:55 +01:00
|
|
|
.InMillisecondsFSinceUnixEpochIgnoringNull())
|
2018-10-02 14:14:11 +02:00
|
|
|
.ToLocalChecked();
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_STRING:
|
2013-12-17 23:04:35 +01:00
|
|
|
return GetV8String(isolate_, CefString(&string_value_));
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_OBJECT:
|
|
|
|
return handle_->GetNewV8Handle(should_persist);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "Invalid type for CefV8ValueImpl";
|
2015-04-20 13:11:11 +02:00
|
|
|
return v8::Local<v8::Value>();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
bool CefV8ValueImpl::IsValid() {
|
2013-06-27 00:33:44 +02:00
|
|
|
if (!CEF_V8_HAS_ISOLATE() || type_ == TYPE_INVALID ||
|
|
|
|
(type_ == TYPE_OBJECT &&
|
2017-05-17 11:29:28 +02:00
|
|
|
(!handle_->BelongsToCurrentThread() || !handle_->IsValid()))) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefV8ValueImpl::IsUndefined() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
|
|
|
return (type_ == TYPE_UNDEFINED);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsNull() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
|
|
|
return (type_ == TYPE_NULL);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsBool() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
|
|
|
return (type_ == TYPE_BOOL);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsInt() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
2024-04-12 17:37:33 +02:00
|
|
|
return type_ == TYPE_INT ||
|
|
|
|
(type_ == TYPE_UINT && uint_value_ <= kMaxInt32AsUint32);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsUInt() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
2024-04-12 17:37:33 +02:00
|
|
|
return type_ == TYPE_UINT || (type_ == TYPE_INT && int_value_ >= 0);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsDouble() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
|
|
|
return (type_ == TYPE_INT || type_ == TYPE_UINT || type_ == TYPE_DOUBLE);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsDate() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
|
|
|
return (type_ == TYPE_DATE);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsString() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
|
|
|
return (type_ == TYPE_STRING);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsObject() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
|
|
|
return (type_ == TYPE_OBJECT);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsArray() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_MLT_RETURN(false);
|
|
|
|
if (type_ == TYPE_OBJECT) {
|
2013-10-16 02:25:38 +02:00
|
|
|
v8::HandleScope handle_scope(handle_->isolate());
|
2013-06-27 00:33:44 +02:00
|
|
|
return handle_->GetNewV8Handle(false)->IsArray();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2018-04-10 21:37:33 +02:00
|
|
|
bool CefV8ValueImpl::IsArrayBuffer() {
|
|
|
|
CEF_V8_REQUIRE_MLT_RETURN(false);
|
|
|
|
if (type_ == TYPE_OBJECT) {
|
|
|
|
v8::HandleScope handle_scope(handle_->isolate());
|
|
|
|
return handle_->GetNewV8Handle(false)->IsArrayBuffer();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefV8ValueImpl::IsFunction() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_MLT_RETURN(false);
|
|
|
|
if (type_ == TYPE_OBJECT) {
|
2013-10-16 02:25:38 +02:00
|
|
|
v8::HandleScope handle_scope(handle_->isolate());
|
2013-06-27 00:33:44 +02:00
|
|
|
return handle_->GetNewV8Handle(false)->IsFunction();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-11 20:54:32 +02:00
|
|
|
bool CefV8ValueImpl::IsPromise() {
|
|
|
|
CEF_V8_REQUIRE_MLT_RETURN(false);
|
|
|
|
if (type_ == TYPE_OBJECT) {
|
|
|
|
v8::HandleScope handle_scope(handle_->isolate());
|
|
|
|
return handle_->GetNewV8Handle(false)->IsPromise();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
bool CefV8ValueImpl::IsSame(CefRefPtr<CefV8Value> that) {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_MLT_RETURN(false);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-06-27 00:33:44 +02:00
|
|
|
CefV8ValueImpl* thatValue = static_cast<CefV8ValueImpl*>(that.get());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!thatValue || !thatValue->IsValid() || type_ != thatValue->type_) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-06-27 00:33:44 +02:00
|
|
|
switch (type_) {
|
|
|
|
case TYPE_UNDEFINED:
|
|
|
|
case TYPE_NULL:
|
|
|
|
return true;
|
|
|
|
case TYPE_BOOL:
|
|
|
|
return (bool_value_ == thatValue->bool_value_);
|
|
|
|
case TYPE_INT:
|
|
|
|
return (int_value_ == thatValue->int_value_);
|
|
|
|
case TYPE_UINT:
|
|
|
|
return (uint_value_ == thatValue->uint_value_);
|
|
|
|
case TYPE_DOUBLE:
|
|
|
|
return (double_value_ == thatValue->double_value_);
|
|
|
|
case TYPE_DATE:
|
2022-05-31 22:28:43 +02:00
|
|
|
return (date_value_.val == thatValue->date_value_.val);
|
2013-06-27 00:33:44 +02:00
|
|
|
case TYPE_STRING:
|
|
|
|
return (CefString(&string_value_) ==
|
|
|
|
CefString(&thatValue->string_value_));
|
|
|
|
case TYPE_OBJECT: {
|
|
|
|
return (handle_->GetPersistentV8Handle() ==
|
|
|
|
thatValue->handle_->GetPersistentV8Handle());
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-06-27 00:33:44 +02:00
|
|
|
return false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::GetBoolValue() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == TYPE_BOOL) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return bool_value_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-06-27 00:33:44 +02:00
|
|
|
return false;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
int32_t CefV8ValueImpl::GetIntValue() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(0);
|
2024-04-12 17:37:33 +02:00
|
|
|
if (type_ == TYPE_INT) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return int_value_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2024-04-12 17:37:33 +02:00
|
|
|
if (type_ == TYPE_UINT && uint_value_ <= kMaxInt32AsUint32) {
|
|
|
|
return static_cast<int32_t>(uint_value_);
|
|
|
|
}
|
2013-06-27 00:33:44 +02:00
|
|
|
return 0;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
uint32_t CefV8ValueImpl::GetUIntValue() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(0);
|
2024-04-12 17:37:33 +02:00
|
|
|
if (type_ == TYPE_UINT) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return uint_value_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2024-04-12 17:37:33 +02:00
|
|
|
if (type_ == TYPE_INT && int_value_ >= 0) {
|
|
|
|
return static_cast<uint32_t>(int_value_);
|
|
|
|
}
|
2013-06-27 00:33:44 +02:00
|
|
|
return 0;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double CefV8ValueImpl::GetDoubleValue() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(0.);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == TYPE_DOUBLE) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return double_value_;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (type_ == TYPE_INT) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return int_value_;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (type_ == TYPE_UINT) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return uint_value_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-06-27 00:33:44 +02:00
|
|
|
return 0.;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2022-05-31 22:28:43 +02:00
|
|
|
CefBaseTime CefV8ValueImpl::GetDateValue() {
|
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(CefBaseTime());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == TYPE_DATE) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return date_value_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-05-31 22:28:43 +02:00
|
|
|
return CefBaseTime();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefV8ValueImpl::GetStringValue() {
|
|
|
|
CefString rv;
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(rv);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (type_ == TYPE_STRING) {
|
2013-06-27 00:33:44 +02:00
|
|
|
rv = CefString(&string_value_);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::IsUserCreated() {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2015-12-09 17:10:16 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2020-01-15 14:36:24 +01:00
|
|
|
return (tracker != nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::HasException() {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return (last_exception_.get() != nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Exception> CefV8ValueImpl::GetException() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return last_exception_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::ClearException() {
|
2012-08-04 02:59:58 +02:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
last_exception_ = nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::WillRethrowExceptions() {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
|
|
|
return rethrow_exceptions_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::SetRethrowExceptions(bool rethrow) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
|
|
|
rethrow_exceptions_ = rethrow;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::HasValue(const CefString& key) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2016-01-06 20:20:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2016-01-06 20:20:54 +01:00
|
|
|
return obj->Has(context, GetV8String(isolate, key)).FromJust();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::HasValue(int index) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
|
|
|
if (index < 0) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid input parameter";
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2016-01-06 20:20:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2016-01-06 20:20:54 +01:00
|
|
|
return obj->Has(context, index).FromJust();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::DeleteValue(const CefString& key) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2016-01-06 20:20:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
2018-11-03 02:15:09 +01:00
|
|
|
v8::Maybe<bool> del = obj->Delete(context, GetV8String(isolate, key));
|
|
|
|
return (!HasCaught(context, try_catch) && del.FromJust());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::DeleteValue(int index) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
|
|
|
if (index < 0) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid input parameter";
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2016-01-06 20:20:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
2016-01-06 20:20:54 +01:00
|
|
|
v8::Maybe<bool> del = obj->Delete(context, index);
|
|
|
|
return (!HasCaught(context, try_catch) && del.FromJust());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(const CefString& key) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2016-01-06 20:20:54 +01:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
2019-07-16 19:59:21 +02:00
|
|
|
v8::MaybeLocal<v8::Value> ret_value =
|
|
|
|
obj->Get(context, GetV8String(isolate, key));
|
|
|
|
if (!HasCaught(context, try_catch) && !ret_value.IsEmpty()) {
|
|
|
|
return new CefV8ValueImpl(isolate, context, ret_value.ToLocalChecked());
|
|
|
|
}
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> CefV8ValueImpl::GetValue(int index) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
if (index < 0) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid input parameter";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2016-01-06 20:20:54 +01:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
2019-07-16 19:59:21 +02:00
|
|
|
v8::MaybeLocal<v8::Value> ret_value =
|
|
|
|
obj->Get(context, v8::Number::New(isolate, index));
|
|
|
|
if (!HasCaught(context, try_catch) && !ret_value.IsEmpty()) {
|
|
|
|
return new CefV8ValueImpl(isolate, context, ret_value.ToLocalChecked());
|
|
|
|
}
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::SetValue(const CefString& key,
|
|
|
|
CefRefPtr<CefV8Value> value,
|
|
|
|
PropertyAttribute attribute) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
|
|
|
CefV8ValueImpl* impl = static_cast<CefV8ValueImpl*>(value.get());
|
2012-12-30 22:16:59 +01:00
|
|
|
if (impl && impl->IsValid()) {
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2016-01-06 20:20:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
v8::Local<v8::Value> v8value = handle_->GetNewV8Handle(false);
|
|
|
|
v8::Local<v8::Object> obj = v8value->ToObject(context).ToLocalChecked();
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
2014-09-04 19:53:40 +02:00
|
|
|
// TODO(cef): This usage may not exactly match the previous implementation.
|
2016-01-06 20:20:54 +01:00
|
|
|
// Set will trigger interceptors and/or accessors whereas DefineOwnProperty
|
|
|
|
// will not. It might be better to split this functionality into separate
|
|
|
|
// methods.
|
2014-09-04 19:53:40 +02:00
|
|
|
if (attribute == V8_PROPERTY_ATTRIBUTE_NONE) {
|
2017-05-17 11:29:28 +02:00
|
|
|
v8::Maybe<bool> set =
|
|
|
|
obj->Set(context, GetV8String(isolate, key), impl->GetV8Value(true));
|
2016-01-06 20:20:54 +01:00
|
|
|
return (!HasCaught(context, try_catch) && set.FromJust());
|
2014-09-04 19:53:40 +02:00
|
|
|
} else {
|
2016-01-06 20:20:54 +01:00
|
|
|
v8::Maybe<bool> set = obj->DefineOwnProperty(
|
2017-05-17 11:29:28 +02:00
|
|
|
context, GetV8String(isolate, key), impl->GetV8Value(true),
|
2016-01-06 20:20:54 +01:00
|
|
|
static_cast<v8::PropertyAttribute>(attribute));
|
|
|
|
return (!HasCaught(context, try_catch) && set.FromJust());
|
2014-09-04 19:53:40 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid input parameter";
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::SetValue(int index, CefRefPtr<CefV8Value> value) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
|
|
|
if (index < 0) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid input parameter";
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefV8ValueImpl* impl = static_cast<CefV8ValueImpl*>(value.get());
|
2012-12-30 22:16:59 +01:00
|
|
|
if (impl && impl->IsValid()) {
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-01-06 20:20:54 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2016-01-06 20:20:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-26 21:30:45 +02:00
|
|
|
v8::Local<v8::Value> v8value = handle_->GetNewV8Handle(false);
|
|
|
|
v8::Local<v8::Object> obj = v8value->ToObject(context).ToLocalChecked();
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
2016-01-06 20:20:54 +01:00
|
|
|
v8::Maybe<bool> set = obj->Set(context, index, impl->GetV8Value(true));
|
|
|
|
return (!HasCaught(context, try_catch) && set.FromJust());
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid input parameter";
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
bool CefV8ValueImpl::SetValue(const CefString& key,
|
|
|
|
AccessControl settings,
|
2012-04-03 03:34:16 +02:00
|
|
|
PropertyAttribute attribute) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2015-12-09 17:10:16 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefV8Accessor> accessorPtr;
|
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2012-04-03 03:34:16 +02:00
|
|
|
accessorPtr = tracker->GetAccessor();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Verify that an accessor exists for this object.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!accessorPtr.get()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
v8::AccessorNameGetterCallback getter = AccessorNameGetterCallbackImpl;
|
|
|
|
v8::AccessorNameSetterCallback setter =
|
2017-05-17 11:29:28 +02:00
|
|
|
(attribute & V8_PROPERTY_ATTRIBUTE_READONLY)
|
2020-01-15 14:36:24 +01:00
|
|
|
? nullptr
|
2017-05-17 11:29:28 +02:00
|
|
|
: AccessorNameSetterCallbackImpl;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
2017-05-17 11:29:28 +02:00
|
|
|
v8::Maybe<bool> set =
|
|
|
|
obj->SetAccessor(context, GetV8String(isolate, key), getter, setter, obj,
|
|
|
|
static_cast<v8::AccessControl>(settings),
|
|
|
|
static_cast<v8::PropertyAttribute>(attribute));
|
2016-01-06 20:20:54 +01:00
|
|
|
return (!HasCaught(context, try_catch) && set.FromJust());
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::GetKeys(std::vector<CefString>& keys) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2018-09-04 11:43:21 +02:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2018-09-04 11:43:21 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2019-02-01 17:42:40 +01:00
|
|
|
v8::Local<v8::Array> arr_keys =
|
|
|
|
obj->GetPropertyNames(context).ToLocalChecked();
|
2013-06-27 00:33:44 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
uint32_t len = arr_keys->Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2022-09-26 21:30:45 +02:00
|
|
|
v8::Local<v8::Value> arr_value =
|
2019-07-16 19:59:21 +02:00
|
|
|
arr_keys->Get(context, v8::Integer::New(isolate, i)).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
CefString str;
|
2022-09-26 21:30:45 +02:00
|
|
|
GetCefString(isolate, arr_value->ToString(context).ToLocalChecked(), str);
|
2012-04-03 03:34:16 +02:00
|
|
|
keys.push_back(str);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-09 23:07:43 +01:00
|
|
|
bool CefV8ValueImpl::SetUserData(CefRefPtr<CefBaseRefCounted> user_data) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2015-12-09 17:10:16 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2012-04-03 03:34:16 +02:00
|
|
|
if (tracker) {
|
|
|
|
tracker->SetUserData(user_data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-09 23:07:43 +01:00
|
|
|
CefRefPtr<CefBaseRefCounted> CefV8ValueImpl::GetUserData() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2015-12-09 17:10:16 +01:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return tracker->GetUserData();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CefV8ValueImpl::GetExternallyAllocatedMemory() {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(0);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2015-12-09 17:10:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return tracker->GetExternallyAllocatedMemory();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefV8ValueImpl::AdjustExternallyAllocatedMemory(int change_in_bytes) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(0);
|
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2015-12-09 17:10:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return tracker->AdjustExternallyAllocatedMemory(change_in_bytes);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefV8ValueImpl::GetArrayLength() {
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(0);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2018-09-04 11:43:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2013-06-27 00:33:44 +02:00
|
|
|
if (!value->IsArray()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 value is not an array";
|
2013-06-27 00:33:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast(obj);
|
2012-04-03 03:34:16 +02:00
|
|
|
return arr->Length();
|
|
|
|
}
|
|
|
|
|
2018-04-10 21:37:33 +02:00
|
|
|
CefRefPtr<CefV8ArrayBufferReleaseCallback>
|
|
|
|
CefV8ValueImpl::GetArrayBufferReleaseCallback() {
|
2020-02-10 18:10:17 +01:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(nullptr);
|
2018-04-10 21:37:33 +02:00
|
|
|
|
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2018-09-04 11:43:21 +02:00
|
|
|
|
2018-04-10 21:37:33 +02:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2018-04-10 21:37:33 +02:00
|
|
|
}
|
2018-09-04 11:43:21 +02:00
|
|
|
|
2018-04-10 21:37:33 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
|
|
|
if (!value->IsArrayBuffer()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 value is not an array buffer";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2018-04-10 21:37:33 +02:00
|
|
|
}
|
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2018-04-10 21:37:33 +02:00
|
|
|
|
|
|
|
V8TrackArrayBuffer* tracker = V8TrackArrayBuffer::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2018-04-10 21:37:33 +02:00
|
|
|
return tracker->GetReleaseCallback();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-04-10 21:37:33 +02:00
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2018-04-10 21:37:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::NeuterArrayBuffer() {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(0);
|
|
|
|
|
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2018-09-04 11:43:21 +02:00
|
|
|
|
2018-04-10 21:37:33 +02:00
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2018-04-10 21:37:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
|
|
|
if (!value->IsArrayBuffer()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 value is not an array buffer";
|
2018-04-10 21:37:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2018-04-10 21:37:33 +02:00
|
|
|
v8::Local<v8::ArrayBuffer> arr = v8::Local<v8::ArrayBuffer>::Cast(obj);
|
2019-10-01 15:55:16 +02:00
|
|
|
if (!arr->IsDetachable()) {
|
2018-04-10 21:37:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
2024-04-23 22:06:00 +02:00
|
|
|
[[maybe_unused]] auto result = arr->Detach(v8::Local<v8::Value>());
|
2018-04-10 21:37:33 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-10-25 20:20:55 +02:00
|
|
|
size_t CefV8ValueImpl::GetArrayBufferByteLength() {
|
|
|
|
size_t rv = 0;
|
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(rv);
|
|
|
|
if (type_ != TYPE_OBJECT) {
|
|
|
|
DCHECK(false) << "V8 value is not an object";
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
|
|
|
if (!value->IsArrayBuffer()) {
|
|
|
|
DCHECK(false) << "V8 value is not an array buffer";
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
|
|
|
return v8::Local<v8::ArrayBuffer>::Cast(obj)->ByteLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
void* CefV8ValueImpl::GetArrayBufferData() {
|
|
|
|
void* rv = nullptr;
|
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(rv);
|
|
|
|
if (type_ != TYPE_OBJECT) {
|
|
|
|
DCHECK(false) << "V8 value is not an object";
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
|
|
|
if (!value->IsArrayBuffer()) {
|
|
|
|
DCHECK(false) << "V8 value is not an array buffer";
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
|
|
|
v8::Local<v8::ArrayBuffer> arr = v8::Local<v8::ArrayBuffer>::Cast(obj);
|
|
|
|
return arr->Data();
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
CefString CefV8ValueImpl::GetFunctionName() {
|
|
|
|
CefString rv;
|
2013-06-27 00:33:44 +02:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(rv);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2018-09-04 11:43:21 +02:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2013-06-27 00:33:44 +02:00
|
|
|
if (!value->IsFunction()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 value is not a function";
|
2013-06-27 00:33:44 +02:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(obj);
|
2018-09-04 11:43:21 +02:00
|
|
|
GetCefString(handle_->isolate(),
|
|
|
|
v8::Handle<v8::String>::Cast(func->GetName()), rv);
|
2012-04-03 03:34:16 +02:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Handler> CefV8ValueImpl::GetFunctionHandler() {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(nullptr);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-12-09 17:10:16 +01:00
|
|
|
|
|
|
|
v8::Local<v8::Context> context = isolate->GetCurrentContext();
|
|
|
|
if (context.IsEmpty()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "not currently in a V8 context";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2015-12-09 17:10:16 +01:00
|
|
|
}
|
|
|
|
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2013-06-27 00:33:44 +02:00
|
|
|
if (!value->IsFunction()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 value is not a function";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2013-06-27 00:33:44 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context).ToLocalChecked();
|
2015-12-09 17:10:16 +01:00
|
|
|
V8TrackObject* tracker = V8TrackObject::Unwrap(context, obj);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (tracker) {
|
2012-04-03 03:34:16 +02:00
|
|
|
return tracker->GetHandler();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> CefV8ValueImpl::ExecuteFunction(
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefV8Value> object,
|
|
|
|
const CefV8ValueList& arguments) {
|
2012-04-03 03:34:16 +02:00
|
|
|
// An empty context value defaults to the current context.
|
|
|
|
CefRefPtr<CefV8Context> context;
|
|
|
|
return ExecuteFunctionWithContext(context, object, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> CefV8ValueImpl::ExecuteFunctionWithContext(
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefV8Context> context,
|
|
|
|
CefRefPtr<CefV8Value> object,
|
|
|
|
const CefV8ValueList& arguments) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(nullptr);
|
2013-06-27 00:33:44 +02:00
|
|
|
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
2013-06-27 00:33:44 +02:00
|
|
|
if (!value->IsFunction()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 value is not a function";
|
2020-02-10 18:10:17 +01:00
|
|
|
return nullptr;
|
2013-06-27 00:33:44 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-12-30 22:16:59 +01:00
|
|
|
if (context.get() && !context->IsValid()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid V8 context parameter";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-12-30 22:16:59 +01:00
|
|
|
}
|
|
|
|
if (object.get() && (!object->IsValid() || !object->IsObject())) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid V8 object parameter";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-12-30 22:16:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int argc = arguments.size();
|
|
|
|
if (argc > 0) {
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
if (!arguments[i].get() || !arguments[i]->IsValid()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid V8 arguments parameter";
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2012-12-30 22:16:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
v8::Local<v8::Context> context_local;
|
|
|
|
if (context.get()) {
|
|
|
|
CefV8ContextImpl* context_impl =
|
|
|
|
static_cast<CefV8ContextImpl*>(context.get());
|
2013-06-27 00:33:44 +02:00
|
|
|
context_local = context_impl->GetV8Context();
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
2013-12-17 23:04:35 +01:00
|
|
|
context_local = isolate->GetCurrentContext();
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
v8::Context::Scope context_scope(context_local);
|
|
|
|
|
2018-09-04 11:43:21 +02:00
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context_local).ToLocalChecked();
|
2015-04-20 13:11:11 +02:00
|
|
|
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(obj);
|
|
|
|
v8::Local<v8::Object> recv;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2012-12-30 22:16:59 +01:00
|
|
|
// Default to the global object if no object was provided.
|
|
|
|
if (object.get()) {
|
2012-04-03 03:34:16 +02:00
|
|
|
CefV8ValueImpl* recv_impl = static_cast<CefV8ValueImpl*>(object.get());
|
2015-04-20 13:11:11 +02:00
|
|
|
recv = v8::Local<v8::Object>::Cast(recv_impl->GetV8Value(true));
|
2012-04-03 03:34:16 +02:00
|
|
|
} else {
|
|
|
|
recv = context_local->Global();
|
|
|
|
}
|
|
|
|
|
2020-01-15 14:36:24 +01:00
|
|
|
v8::Local<v8::Value>* argv = nullptr;
|
2012-04-03 03:34:16 +02:00
|
|
|
if (argc > 0) {
|
2015-04-20 13:11:11 +02:00
|
|
|
argv = new v8::Local<v8::Value>[argc];
|
2012-10-30 21:49:43 +01:00
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
argv[i] =
|
2013-06-27 00:33:44 +02:00
|
|
|
static_cast<CefV8ValueImpl*>(arguments[i].get())->GetV8Value(true);
|
2012-10-30 21:49:43 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8Value> retval;
|
|
|
|
|
2012-04-24 20:01:48 +02:00
|
|
|
{
|
2015-12-09 17:10:16 +01:00
|
|
|
v8::TryCatch try_catch(isolate);
|
2012-04-24 20:01:48 +02:00
|
|
|
try_catch.SetVerbose(true);
|
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
v8::MaybeLocal<v8::Value> func_rv = blink_glue::CallV8Function(
|
2017-05-17 11:29:28 +02:00
|
|
|
context_local, func, recv, argc, argv, handle_->isolate());
|
2012-04-24 20:01:48 +02:00
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
if (!HasCaught(context_local, try_catch) && !func_rv.IsEmpty()) {
|
2017-05-17 11:29:28 +02:00
|
|
|
retval =
|
|
|
|
new CefV8ValueImpl(isolate, context_local, func_rv.ToLocalChecked());
|
2016-01-06 20:20:54 +01:00
|
|
|
}
|
2012-04-24 20:01:48 +02:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (argv) {
|
2017-05-17 11:29:28 +02:00
|
|
|
delete[] argv;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2022-10-11 20:54:32 +02:00
|
|
|
bool CefV8ValueImpl::ResolvePromise(CefRefPtr<CefV8Value> arg) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
|
|
|
if (!value->IsPromise()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 value is not a Promise";
|
2022-10-11 20:54:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg.get() && !arg->IsValid()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "invalid V8 arg parameter";
|
2022-10-11 20:54:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context_local = isolate->GetCurrentContext();
|
|
|
|
|
|
|
|
v8::Context::Scope context_scope(context_local);
|
|
|
|
|
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context_local).ToLocalChecked();
|
|
|
|
v8::Local<v8::Promise::Resolver> promise =
|
|
|
|
v8::Local<v8::Promise::Resolver>::Cast(obj);
|
|
|
|
|
|
|
|
v8::TryCatch try_catch(isolate);
|
|
|
|
try_catch.SetVerbose(true);
|
|
|
|
|
|
|
|
if (arg.get()) {
|
|
|
|
promise
|
|
|
|
->Resolve(context_local,
|
|
|
|
static_cast<CefV8ValueImpl*>(arg.get())->GetV8Value(true))
|
|
|
|
.ToChecked();
|
|
|
|
} else {
|
|
|
|
promise->Resolve(context_local, v8::Undefined(isolate)).ToChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
return !HasCaught(context_local, try_catch);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8ValueImpl::RejectPromise(const CefString& errorMsg) {
|
|
|
|
CEF_V8_REQUIRE_OBJECT_RETURN(false);
|
|
|
|
|
|
|
|
v8::Isolate* isolate = handle_->isolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Local<v8::Value> value = handle_->GetNewV8Handle(false);
|
|
|
|
if (!value->IsPromise()) {
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false) << "V8 value is not a Promise";
|
2022-10-11 20:54:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Context> context_local = isolate->GetCurrentContext();
|
|
|
|
|
|
|
|
v8::Context::Scope context_scope(context_local);
|
|
|
|
|
|
|
|
v8::Local<v8::Object> obj = value->ToObject(context_local).ToLocalChecked();
|
|
|
|
v8::Local<v8::Promise::Resolver> promise =
|
|
|
|
v8::Local<v8::Promise::Resolver>::Cast(obj);
|
|
|
|
|
|
|
|
v8::TryCatch try_catch(isolate);
|
|
|
|
try_catch.SetVerbose(true);
|
|
|
|
|
|
|
|
promise
|
|
|
|
->Reject(context_local,
|
|
|
|
v8::Exception::Error(GetV8String(isolate, errorMsg)))
|
|
|
|
.ToChecked();
|
|
|
|
|
|
|
|
return !HasCaught(context_local, try_catch);
|
|
|
|
}
|
|
|
|
|
2016-01-06 20:20:54 +01:00
|
|
|
bool CefV8ValueImpl::HasCaught(v8::Local<v8::Context> context,
|
|
|
|
v8::TryCatch& try_catch) {
|
2012-04-03 03:34:16 +02:00
|
|
|
if (try_catch.HasCaught()) {
|
2016-01-06 20:20:54 +01:00
|
|
|
last_exception_ = new CefV8ExceptionImpl(context, try_catch.Message());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (rethrow_exceptions_) {
|
2012-04-03 03:34:16 +02:00
|
|
|
try_catch.ReThrow();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (last_exception_.get()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
last_exception_ = nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-07-25 13:50:35 +02:00
|
|
|
|
|
|
|
// CefV8StackTrace
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefV8StackTrace> CefV8StackTrace::GetCurrent(int frame_limit) {
|
2020-01-15 14:36:24 +01:00
|
|
|
CEF_V8_REQUIRE_ISOLATE_RETURN(nullptr);
|
2012-07-25 13:50:35 +02:00
|
|
|
|
2023-04-04 20:00:13 +02:00
|
|
|
v8::Isolate* isolate = CefV8IsolateManager::Get()->isolate();
|
2013-12-17 23:04:35 +01:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2017-05-17 11:29:28 +02:00
|
|
|
v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(
|
|
|
|
isolate, frame_limit, v8::StackTrace::kDetailed);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (stackTrace.IsEmpty()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-12-17 23:04:35 +01:00
|
|
|
return new CefV8StackTraceImpl(isolate, stackTrace);
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CefV8StackTraceImpl
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefV8StackTraceImpl::CefV8StackTraceImpl(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::StackTrace> handle) {
|
|
|
|
if (!handle.IsEmpty()) {
|
2015-06-06 00:06:48 +02:00
|
|
|
int frame_count = handle->GetFrameCount();
|
|
|
|
if (frame_count > 0) {
|
|
|
|
frames_.reserve(frame_count);
|
2023-01-02 23:59:03 +01:00
|
|
|
for (int i = 0; i < frame_count; ++i) {
|
2015-06-06 00:06:48 +02:00
|
|
|
frames_.push_back(
|
2018-09-04 11:43:21 +02:00
|
|
|
new CefV8StackFrameImpl(isolate, handle->GetFrame(isolate, i)));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-06-06 00:06:48 +02:00
|
|
|
}
|
2013-06-27 00:33:44 +02:00
|
|
|
}
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefV8StackTraceImpl::~CefV8StackTraceImpl() = default;
|
2012-07-25 13:50:35 +02:00
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
bool CefV8StackTraceImpl::IsValid() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return true;
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2012-07-25 13:50:35 +02:00
|
|
|
int CefV8StackTraceImpl::GetFrameCount() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return frames_.size();
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefV8StackFrame> CefV8StackTraceImpl::GetFrame(int index) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (index < 0 || index >= static_cast<int>(frames_.size())) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-06-27 00:33:44 +02:00
|
|
|
return frames_[index];
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CefV8StackFrameImpl
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefV8StackFrameImpl::CefV8StackFrameImpl(v8::Isolate* isolate,
|
2024-01-20 23:48:57 +01:00
|
|
|
v8::Local<v8::StackFrame> handle) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (handle.IsEmpty()) {
|
2013-06-27 00:33:44 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-09-04 11:43:21 +02:00
|
|
|
GetCefString(isolate, handle->GetScriptName(), script_name_);
|
|
|
|
GetCefString(isolate, handle->GetScriptNameOrSourceURL(),
|
|
|
|
script_name_or_source_url_);
|
|
|
|
GetCefString(isolate, handle->GetFunctionName(), function_name_);
|
2013-06-27 00:33:44 +02:00
|
|
|
line_number_ = handle->GetLineNumber();
|
|
|
|
column_ = handle->GetColumn();
|
|
|
|
is_eval_ = handle->IsEval();
|
|
|
|
is_constructor_ = handle->IsConstructor();
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefV8StackFrameImpl::~CefV8StackFrameImpl() = default;
|
2012-07-25 13:50:35 +02:00
|
|
|
|
2012-10-29 22:46:02 +01:00
|
|
|
bool CefV8StackFrameImpl::IsValid() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return true;
|
2012-10-29 22:46:02 +01:00
|
|
|
}
|
|
|
|
|
2012-07-25 13:50:35 +02:00
|
|
|
CefString CefV8StackFrameImpl::GetScriptName() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return script_name_;
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefV8StackFrameImpl::GetScriptNameOrSourceURL() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return script_name_or_source_url_;
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefV8StackFrameImpl::GetFunctionName() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return function_name_;
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CefV8StackFrameImpl::GetLineNumber() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return line_number_;
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int CefV8StackFrameImpl::GetColumn() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return column_;
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8StackFrameImpl::IsEval() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return is_eval_;
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefV8StackFrameImpl::IsConstructor() {
|
2013-06-27 00:33:44 +02:00
|
|
|
return is_constructor_;
|
2012-07-25 13:50:35 +02:00
|
|
|
}
|
2016-02-08 19:47:18 +01:00
|
|
|
|
2018-10-02 14:14:11 +02:00
|
|
|
// Enable deprecation warnings on Windows. See http://crbug.com/585142.
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-10-02 14:14:11 +02:00
|
|
|
#if defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#else
|
2016-02-08 19:47:18 +01:00
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2018-10-02 14:14:11 +02:00
|
|
|
#endif
|