Improvements to v8::Persistent usage (issue #1001):

- Remove V8_USE_UNSAFE_HANDLES dependency.
- Don't create persistent handles for primitive types.
- Don't create persistent handles for stack traces.
- CefV8Value::IsObject() no longer returns true for Date types.
- Fix V8Test.ContextEntered test flakiness.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1293 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2013-06-26 22:33:44 +00:00
parent db530ec5e3
commit 947a99d592
4 changed files with 516 additions and 303 deletions

View File

@@ -20,12 +20,6 @@
'clang_use_chrome_plugins': 0, 'clang_use_chrome_plugins': 0,
}], }],
] ]
}, 'target_defaults': {
'defines': [
# Temporary work-around for v8::Persistent changes.
# See https://code.google.com/p/chromiumembedded/issues/detail?id=1001
'V8_USE_UNSAFE_HANDLES=1',
],
}, 'conditions': [ }, 'conditions': [
['os_posix==1 and OS!="mac" and OS!="android"', { ['os_posix==1 and OS!="mac" and OS!="android"', {
'target_defaults': { 'target_defaults': {

File diff suppressed because it is too large Load Diff

View File

@@ -128,15 +128,19 @@ class CefV8Handle : public CefV8HandleBase {
CefV8Handle(v8::Handle<v8::Context> context, handleType v) CefV8Handle(v8::Handle<v8::Context> context, handleType v)
: CefV8HandleBase(context), : CefV8HandleBase(context),
handle_(persistentType::New(isolate(), v)) { handle_(isolate(), v) {
} }
virtual ~CefV8Handle() { virtual ~CefV8Handle() {
handle_.Dispose(isolate()); handle_.Dispose(isolate());
handle_.Clear(); handle_.Clear();
} }
handleType GetHandle() { handleType GetNewV8Handle() {
DCHECK(IsValid()); DCHECK(IsValid());
return handleType::New(isolate(), handle_);
}
persistentType& GetPersistentV8Handle() {
return handle_; return handle_;
} }
@@ -170,11 +174,9 @@ class CefV8ContextImpl : public CefV8Context {
CefRefPtr<CefV8Value>& retval, CefRefPtr<CefV8Value>& retval,
CefRefPtr<CefV8Exception>& exception) OVERRIDE; CefRefPtr<CefV8Exception>& exception) OVERRIDE;
v8::Local<v8::Context> GetContext(); v8::Handle<v8::Context> GetV8Context();
WebKit::WebFrame* GetWebFrame(); WebKit::WebFrame* GetWebFrame();
v8::Handle<v8::Context> GetHandle() { return handle_->GetHandle(); }
protected: protected:
typedef CefV8Handle<v8::Context> Handle; typedef CefV8Handle<v8::Context> Handle;
scoped_refptr<Handle> handle_; scoped_refptr<Handle> handle_;
@@ -190,9 +192,27 @@ class CefV8ContextImpl : public CefV8Context {
class CefV8ValueImpl : public CefV8Value { class CefV8ValueImpl : public CefV8Value {
public: public:
CefV8ValueImpl(v8::Handle<v8::Value> value, CefTrackNode* tracker = NULL); CefV8ValueImpl();
explicit CefV8ValueImpl(v8::Handle<v8::Value> value);
virtual ~CefV8ValueImpl(); virtual ~CefV8ValueImpl();
// Used for initializing the CefV8ValueImpl. Should be called a single time
// after the CefV8ValueImpl is created.
void InitFromV8Value(v8::Handle<v8::Value> value);
void InitUndefined();
void InitNull();
void InitBool(bool value);
void InitInt(int32 value);
void InitUInt(uint32 value);
void InitDouble(double value);
void InitDate(const CefTime& value);
void InitString(CefString& value);
void InitObject(v8::Handle<v8::Value> value, CefTrackNode* tracker);
// Creates a new V8 value for the underlying value or returns the existing
// object handle.
v8::Handle<v8::Value> GetV8Value(bool should_persist);
virtual bool IsValid() OVERRIDE; virtual bool IsValid() OVERRIDE;
virtual bool IsUndefined() OVERRIDE; virtual bool IsUndefined() OVERRIDE;
virtual bool IsNull() OVERRIDE; virtual bool IsNull() OVERRIDE;
@@ -245,10 +265,6 @@ class CefV8ValueImpl : public CefV8Value {
CefRefPtr<CefV8Value> object, CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments) OVERRIDE; const CefV8ValueList& arguments) OVERRIDE;
v8::Handle<v8::Value> GetHandle(bool should_persist) {
return handle_->GetHandle(should_persist);
}
protected: protected:
// Test for and record any exception. // Test for and record any exception.
bool HasCaught(v8::TryCatch& try_catch); bool HasCaught(v8::TryCatch& try_catch);
@@ -260,16 +276,20 @@ class CefV8ValueImpl : public CefV8Value {
Handle(v8::Handle<v8::Context> context, handleType v, CefTrackNode* tracker) Handle(v8::Handle<v8::Context> context, handleType v, CefTrackNode* tracker)
: CefV8HandleBase(context), : CefV8HandleBase(context),
handle_(persistentType::New(isolate(), v)), handle_(isolate(), v),
tracker_(tracker), tracker_(tracker),
should_persist_(false) { should_persist_(false) {
} }
virtual ~Handle(); virtual ~Handle();
handleType GetHandle(bool should_persist) { handleType GetNewV8Handle(bool should_persist) {
DCHECK(IsValid()); DCHECK(IsValid());
if (should_persist && !should_persist_) if (should_persist && !should_persist_)
should_persist_ = true; should_persist_ = true;
return handleType::New(isolate(), handle_);
}
persistentType& GetPersistentV8Handle() {
return handle_; return handle_;
} }
@@ -285,6 +305,30 @@ class CefV8ValueImpl : public CefV8Value {
DISALLOW_COPY_AND_ASSIGN(Handle); DISALLOW_COPY_AND_ASSIGN(Handle);
}; };
enum {
TYPE_INVALID = 0,
TYPE_UNDEFINED,
TYPE_NULL,
TYPE_BOOL,
TYPE_INT,
TYPE_UINT,
TYPE_DOUBLE,
TYPE_DATE,
TYPE_STRING,
TYPE_OBJECT,
} type_;
union {
bool bool_value_;
int32 int_value_;
uint32 uint_value_;
double double_value_;
cef_time_t date_value_;
cef_string_t string_value_;
};
// Used with Object, Function and Array types.
scoped_refptr<Handle> handle_; scoped_refptr<Handle> handle_;
CefRefPtr<CefV8Exception> last_exception_; CefRefPtr<CefV8Exception> last_exception_;
@@ -303,11 +347,8 @@ class CefV8StackTraceImpl : public CefV8StackTrace {
virtual int GetFrameCount() OVERRIDE; virtual int GetFrameCount() OVERRIDE;
virtual CefRefPtr<CefV8StackFrame> GetFrame(int index) OVERRIDE; virtual CefRefPtr<CefV8StackFrame> GetFrame(int index) OVERRIDE;
v8::Handle<v8::StackTrace> GetHandle() { return handle_->GetHandle(); }
protected: protected:
typedef CefV8Handle<v8::StackTrace> Handle; std::vector<CefRefPtr<CefV8StackFrame> > frames_;
scoped_refptr<Handle> handle_;
IMPLEMENT_REFCOUNTING(CefV8StackTraceImpl); IMPLEMENT_REFCOUNTING(CefV8StackTraceImpl);
DISALLOW_COPY_AND_ASSIGN(CefV8StackTraceImpl); DISALLOW_COPY_AND_ASSIGN(CefV8StackTraceImpl);
@@ -327,11 +368,14 @@ class CefV8StackFrameImpl : public CefV8StackFrame {
virtual bool IsEval() OVERRIDE; virtual bool IsEval() OVERRIDE;
virtual bool IsConstructor() OVERRIDE; virtual bool IsConstructor() OVERRIDE;
v8::Handle<v8::StackFrame> GetHandle() { return handle_->GetHandle(); }
protected: protected:
typedef CefV8Handle<v8::StackFrame> Handle; CefString script_name_;
scoped_refptr<Handle> handle_; CefString script_name_or_source_url_;
CefString function_name_;
int line_number_;
int column_;
bool is_eval_;
bool is_constructor_;
IMPLEMENT_REFCOUNTING(CefV8StackFrameImpl); IMPLEMENT_REFCOUNTING(CefV8StackFrameImpl);
DISALLOW_COPY_AND_ASSIGN(CefV8StackFrameImpl); DISALLOW_COPY_AND_ASSIGN(CefV8StackFrameImpl);

View File

@@ -364,7 +364,6 @@ class V8RendererTest : public ClientApp::RenderDelegate {
CefRefPtr<CefV8Value> value = CefV8Value::CreateDate(date); CefRefPtr<CefV8Value> value = CefV8Value::CreateDate(date);
EXPECT_TRUE(value.get()); EXPECT_TRUE(value.get());
EXPECT_TRUE(value->IsDate()); EXPECT_TRUE(value->IsDate());
EXPECT_TRUE(value->IsObject());
EXPECT_EQ(date.GetTimeT(), value->GetDateValue().GetTimeT()); EXPECT_EQ(date.GetTimeT(), value->GetDateValue().GetTimeT());
// Exit the V8 context. // Exit the V8 context.
@@ -377,6 +376,7 @@ class V8RendererTest : public ClientApp::RenderDelegate {
EXPECT_FALSE(value->IsFunction()); EXPECT_FALSE(value->IsFunction());
EXPECT_FALSE(value->IsInt()); EXPECT_FALSE(value->IsInt());
EXPECT_FALSE(value->IsUInt()); EXPECT_FALSE(value->IsUInt());
EXPECT_FALSE(value->IsObject());
EXPECT_FALSE(value->IsNull()); EXPECT_FALSE(value->IsNull());
EXPECT_FALSE(value->IsString()); EXPECT_FALSE(value->IsString());
@@ -1995,7 +1995,7 @@ class V8TestHandler : public TestHandler {
} }
} else { } else {
const std::string& url = frame->GetURL(); const std::string& url = frame->GetURL();
if (url != kV8NavTestUrl && if (url != kV8NavTestUrl && url != kV8ContextParentTestUrl &&
url.find("http://tests/") != std::string::npos) { url.find("http://tests/") != std::string::npos) {
// Run the test. // Run the test.
CefRefPtr<CefProcessMessage> return_msg = CefRefPtr<CefProcessMessage> return_msg =