Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Unified Diff: test/cctest/test-api.cc

Issue 7344013: Expose APIs for detecting boxed primitives, native errors and Math. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/factory.cc ('K') | « src/factory.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 8d8770f13236637d6bfc727aa5a0facbe398611c..05fc39f46804b06eeb03974ef179a273f711c0b2 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1026,6 +1026,101 @@ THREADED_TEST(OutOfSignedRangeUnsignedInteger) {
}
+THREADED_TEST(IsNativeError) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::Handle<Value> syntax_error = CompileRun(
+ "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; ");
+ CHECK(syntax_error->IsNativeError());
+ v8::Handle<Value> not_error = CompileRun("{a:42}");
+ CHECK(!not_error->IsNativeError());
+ v8::Handle<Value> not_object = CompileRun("42");
+ CHECK(!not_object->IsNativeError());
+}
+
+
+THREADED_TEST(IsMath) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::Handle<Value> maybe_math = CompileRun("Math");
+ CHECK(maybe_math->IsMath());
+ v8::Handle<Value> maybe_not = CompileRun("{a: 1}");
+ CHECK(!maybe_not->IsMath());
+ v8::Handle<Value> not_object = CompileRun("1");
+ CHECK(!not_object->IsMath());
+}
+
+
+THREADED_TEST(BoxedString) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")");
+ CHECK(boxed_string->IsBoxedString());
+ v8::Handle<Value> unboxed_string = CompileRun("\"test\"");
+ CHECK(!unboxed_string->IsBoxedString());
+ v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)");
+ CHECK(!boxed_not_string->IsBoxedString());
+ v8::Handle<Value> not_object = CompileRun("0");
+ CHECK(!not_object->IsBoxedString());
+ v8::Handle<v8::BoxedString> as_boxed = boxed_string.As<v8::BoxedString>();
+ CHECK(!as_boxed.IsEmpty());
+ Local<v8::String> the_string = as_boxed->StringValue();
+ CHECK(!the_string.IsEmpty());
+ ExpectObject("\"test\"", the_string);
+ v8::Handle<v8::Value> new_boxed_string = v8::BoxedString::New(the_string);
+ CHECK(new_boxed_string->IsBoxedString());
+ as_boxed = new_boxed_string.As<v8::BoxedString>();
+ the_string = as_boxed->StringValue();
+ CHECK(!the_string.IsEmpty());
+ ExpectObject("\"test\"", the_string);
+}
+
+
+THREADED_TEST(BoxedNumber) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::Handle<Value> boxed_number = CompileRun("new Number(42)");
+ CHECK(boxed_number->IsBoxedNumber());
+ v8::Handle<Value> unboxed_number = CompileRun("42");
+ CHECK(!unboxed_number->IsBoxedNumber());
+ v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)");
+ CHECK(!boxed_not_number->IsBoxedNumber());
+ v8::Handle<v8::BoxedNumber> as_boxed = boxed_number.As<v8::BoxedNumber>();
+ CHECK(!as_boxed.IsEmpty());
+ double the_number = as_boxed->NumberValue();
+ CHECK_EQ(42.0, the_number);
+ v8::Handle<v8::Value> new_boxed_number = v8::BoxedNumber::New(43);
+ CHECK(new_boxed_number->IsBoxedNumber());
+ as_boxed = new_boxed_number.As<v8::BoxedNumber>();
+ the_number = as_boxed->NumberValue();
+ CHECK_EQ(43.0, the_number);
+}
+
+
+THREADED_TEST(BoxedBoolean) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)");
+ CHECK(boxed_boolean->IsBoxedBoolean());
+ v8::Handle<Value> unboxed_boolean = CompileRun("true");
+ CHECK(!unboxed_boolean->IsBoxedBoolean());
+ v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)");
+ CHECK(!boxed_not_boolean->IsBoxedBoolean());
+ v8::Handle<v8::BoxedBoolean> as_boxed = boxed_boolean.As<v8::BoxedBoolean>();
+ CHECK(!as_boxed.IsEmpty());
+ bool the_boolean = as_boxed->BooleanValue();
+ CHECK_EQ(true, the_boolean);
+ v8::Handle<v8::Value> boxed_true = v8::BoxedBoolean::New(true);
+ v8::Handle<v8::Value> boxed_false = v8::BoxedBoolean::New(false);
+ CHECK(boxed_true->IsBoxedBoolean());
+ CHECK(boxed_false->IsBoxedBoolean());
+ as_boxed = boxed_true.As<v8::BoxedBoolean>();
+ CHECK_EQ(true, as_boxed->BooleanValue());
+ as_boxed = boxed_false.As<v8::BoxedBoolean>();
+ CHECK_EQ(false, as_boxed->BooleanValue());
+}
+
+
THREADED_TEST(Number) {
v8::HandleScope scope;
LocalContext env;
« src/factory.cc ('K') | « src/factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698