diff options
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/fxjs_v8.cpp | 6 | ||||
-rw-r--r-- | fxjs/fxjs_v8.h | 1 | ||||
-rw-r--r-- | fxjs/fxjs_v8_embeddertest.cpp | 16 |
3 files changed, 21 insertions, 2 deletions
diff --git a/fxjs/fxjs_v8.cpp b/fxjs/fxjs_v8.cpp index 4c6398870d..441848205f 100644 --- a/fxjs/fxjs_v8.cpp +++ b/fxjs/fxjs_v8.cpp @@ -664,7 +664,11 @@ v8::Local<v8::String> CFXJS_Engine::NewString(const WideStringView& str) { } v8::Local<v8::Value> CFXJS_Engine::NewNull() { - return v8::Local<v8::Value>(); + return v8::Null(m_isolate); +} + +v8::Local<v8::Value> CFXJS_Engine::NewUndefined() { + return v8::Undefined(m_isolate); } v8::Local<v8::Date> CFXJS_Engine::NewDate(double d) { diff --git a/fxjs/fxjs_v8.h b/fxjs/fxjs_v8.h index f5e52411f3..eee85e031d 100644 --- a/fxjs/fxjs_v8.h +++ b/fxjs/fxjs_v8.h @@ -179,6 +179,7 @@ class CFXJS_Engine { v8::Local<v8::Object> GetThisObj(); v8::Local<v8::Value> NewNull(); + v8::Local<v8::Value> NewUndefined(); v8::Local<v8::Array> NewArray(); v8::Local<v8::Number> NewNumber(int number); v8::Local<v8::Number> NewNumber(double number); diff --git a/fxjs/fxjs_v8_embeddertest.cpp b/fxjs/fxjs_v8_embeddertest.cpp index 53fe8f268b..d975264d1d 100644 --- a/fxjs/fxjs_v8_embeddertest.cpp +++ b/fxjs/fxjs_v8_embeddertest.cpp @@ -98,11 +98,25 @@ TEST_F(FXJSV8EmbedderTest, NewNull) { EXPECT_FALSE(engine()->ToBoolean(nullz)); EXPECT_EQ(0, engine()->ToInt32(nullz)); EXPECT_EQ(0.0, engine()->ToDouble(nullz)); - EXPECT_EQ(L"", engine()->ToWideString(nullz)); + EXPECT_EQ(L"null", engine()->ToWideString(nullz)); EXPECT_TRUE(engine()->ToObject(nullz).IsEmpty()); EXPECT_TRUE(engine()->ToArray(nullz).IsEmpty()); } +TEST_F(FXJSV8EmbedderTest, NewUndefined) { + v8::Isolate::Scope isolate_scope(isolate()); + v8::HandleScope handle_scope(isolate()); + v8::Context::Scope context_scope(GetV8Context()); + + auto undef = engine()->NewUndefined(); + EXPECT_FALSE(engine()->ToBoolean(undef)); + EXPECT_EQ(0, engine()->ToInt32(undef)); + EXPECT_TRUE(std::isnan(engine()->ToDouble(undef))); + EXPECT_EQ(L"undefined", engine()->ToWideString(undef)); + EXPECT_TRUE(engine()->ToObject(undef).IsEmpty()); + EXPECT_TRUE(engine()->ToArray(undef).IsEmpty()); +} + TEST_F(FXJSV8EmbedderTest, NewBoolean) { v8::Isolate::Scope isolate_scope(isolate()); v8::HandleScope handle_scope(isolate()); |