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

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: Get rid of unclear 'box' comments/strings. 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
« include/v8.h ('K') | « src/api.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..9769fb79ab5a04410343a424cbfc64095054c639 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -1026,6 +1026,90 @@ 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(StringObject) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")");
+ CHECK(boxed_string->IsStringObject());
+ v8::Handle<Value> unboxed_string = CompileRun("\"test\"");
+ CHECK(!unboxed_string->IsStringObject());
+ v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)");
+ CHECK(!boxed_not_string->IsStringObject());
+ v8::Handle<Value> not_object = CompileRun("0");
+ CHECK(!not_object->IsStringObject());
+ v8::Handle<v8::StringObject> as_boxed = boxed_string.As<v8::StringObject>();
+ 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::StringObject::New(the_string);
+ CHECK(new_boxed_string->IsStringObject());
+ as_boxed = new_boxed_string.As<v8::StringObject>();
+ the_string = as_boxed->StringValue();
+ CHECK(!the_string.IsEmpty());
+ ExpectObject("\"test\"", the_string);
+}
+
+
+THREADED_TEST(NumberObject) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::Handle<Value> boxed_number = CompileRun("new Number(42)");
+ CHECK(boxed_number->IsNumberObject());
+ v8::Handle<Value> unboxed_number = CompileRun("42");
+ CHECK(!unboxed_number->IsNumberObject());
+ v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)");
+ CHECK(!boxed_not_number->IsNumberObject());
+ v8::Handle<v8::NumberObject> as_boxed = boxed_number.As<v8::NumberObject>();
+ CHECK(!as_boxed.IsEmpty());
+ double the_number = as_boxed->NumberValue();
+ CHECK_EQ(42.0, the_number);
+ v8::Handle<v8::Value> new_boxed_number = v8::NumberObject::New(43);
+ CHECK(new_boxed_number->IsNumberObject());
+ as_boxed = new_boxed_number.As<v8::NumberObject>();
+ the_number = as_boxed->NumberValue();
+ CHECK_EQ(43.0, the_number);
+}
+
+
+THREADED_TEST(BooleanObject) {
+ v8::HandleScope scope;
+ LocalContext env;
+ v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)");
+ CHECK(boxed_boolean->IsBooleanObject());
+ v8::Handle<Value> unboxed_boolean = CompileRun("true");
+ CHECK(!unboxed_boolean->IsBooleanObject());
+ v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)");
+ CHECK(!boxed_not_boolean->IsBooleanObject());
+ v8::Handle<v8::BooleanObject> as_boxed =
+ boxed_boolean.As<v8::BooleanObject>();
+ CHECK(!as_boxed.IsEmpty());
+ bool the_boolean = as_boxed->BooleanValue();
+ CHECK_EQ(true, the_boolean);
+ v8::Handle<v8::Value> boxed_true = v8::BooleanObject::New(true);
+ v8::Handle<v8::Value> boxed_false = v8::BooleanObject::New(false);
+ CHECK(boxed_true->IsBooleanObject());
+ CHECK(boxed_false->IsBooleanObject());
+ as_boxed = boxed_true.As<v8::BooleanObject>();
+ CHECK_EQ(true, as_boxed->BooleanValue());
+ as_boxed = boxed_false.As<v8::BooleanObject>();
+ CHECK_EQ(false, as_boxed->BooleanValue());
+}
+
+
THREADED_TEST(Number) {
v8::HandleScope scope;
LocalContext env;
« include/v8.h ('K') | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698