OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 v8::HandleScope scope; | 1019 v8::HandleScope scope; |
1020 LocalContext env; | 1020 LocalContext env; |
1021 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1; | 1021 uint32_t INT32_MAX_AS_UINT = (1U << 31) - 1; |
1022 uint32_t value = INT32_MAX_AS_UINT + 1; | 1022 uint32_t value = INT32_MAX_AS_UINT + 1; |
1023 CHECK(value > INT32_MAX_AS_UINT); // No overflow. | 1023 CHECK(value > INT32_MAX_AS_UINT); // No overflow. |
1024 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); | 1024 Local<v8::Integer> value_obj = v8::Integer::NewFromUnsigned(value); |
1025 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); | 1025 CHECK_EQ(static_cast<int64_t>(value), value_obj->Value()); |
1026 } | 1026 } |
1027 | 1027 |
1028 | 1028 |
| 1029 THREADED_TEST(IsNativeError) { |
| 1030 v8::HandleScope scope; |
| 1031 LocalContext env; |
| 1032 v8::Handle<Value> syntax_error = CompileRun( |
| 1033 "var out = 0; try { eval(\"#\"); } catch(x) { out = x; } out; "); |
| 1034 CHECK(syntax_error->IsNativeError()); |
| 1035 v8::Handle<Value> not_error = CompileRun("{a:42}"); |
| 1036 CHECK(!not_error->IsNativeError()); |
| 1037 v8::Handle<Value> not_object = CompileRun("42"); |
| 1038 CHECK(!not_object->IsNativeError()); |
| 1039 } |
| 1040 |
| 1041 |
| 1042 THREADED_TEST(IsMath) { |
| 1043 v8::HandleScope scope; |
| 1044 LocalContext env; |
| 1045 v8::Handle<Value> maybe_math = CompileRun("Math"); |
| 1046 CHECK(maybe_math->IsMath()); |
| 1047 v8::Handle<Value> maybe_not = CompileRun("{a: 1}"); |
| 1048 CHECK(!maybe_not->IsMath()); |
| 1049 v8::Handle<Value> not_object = CompileRun("1"); |
| 1050 CHECK(!not_object->IsMath()); |
| 1051 } |
| 1052 |
| 1053 |
| 1054 THREADED_TEST(BoxedString) { |
| 1055 v8::HandleScope scope; |
| 1056 LocalContext env; |
| 1057 v8::Handle<Value> boxed_string = CompileRun("new String(\"test\")"); |
| 1058 CHECK(boxed_string->IsBoxedString()); |
| 1059 v8::Handle<Value> unboxed_string = CompileRun("\"test\""); |
| 1060 CHECK(!unboxed_string->IsBoxedString()); |
| 1061 v8::Handle<Value> boxed_not_string = CompileRun("new Number(42)"); |
| 1062 CHECK(!boxed_not_string->IsBoxedString()); |
| 1063 v8::Handle<Value> not_object = CompileRun("0"); |
| 1064 CHECK(!not_object->IsBoxedString()); |
| 1065 v8::Handle<v8::BoxedString> as_boxed = boxed_string.As<v8::BoxedString>(); |
| 1066 CHECK(!as_boxed.IsEmpty()); |
| 1067 Local<v8::String> the_string = as_boxed->StringValue(); |
| 1068 CHECK(!the_string.IsEmpty()); |
| 1069 ExpectObject("\"test\"", the_string); |
| 1070 v8::Handle<v8::Value> new_boxed_string = v8::BoxedString::New(the_string); |
| 1071 CHECK(new_boxed_string->IsBoxedString()); |
| 1072 as_boxed = new_boxed_string.As<v8::BoxedString>(); |
| 1073 the_string = as_boxed->StringValue(); |
| 1074 CHECK(!the_string.IsEmpty()); |
| 1075 ExpectObject("\"test\"", the_string); |
| 1076 } |
| 1077 |
| 1078 |
| 1079 THREADED_TEST(BoxedNumber) { |
| 1080 v8::HandleScope scope; |
| 1081 LocalContext env; |
| 1082 v8::Handle<Value> boxed_number = CompileRun("new Number(42)"); |
| 1083 CHECK(boxed_number->IsBoxedNumber()); |
| 1084 v8::Handle<Value> unboxed_number = CompileRun("42"); |
| 1085 CHECK(!unboxed_number->IsBoxedNumber()); |
| 1086 v8::Handle<Value> boxed_not_number = CompileRun("new Boolean(false)"); |
| 1087 CHECK(!boxed_not_number->IsBoxedNumber()); |
| 1088 v8::Handle<v8::BoxedNumber> as_boxed = boxed_number.As<v8::BoxedNumber>(); |
| 1089 CHECK(!as_boxed.IsEmpty()); |
| 1090 double the_number = as_boxed->NumberValue(); |
| 1091 CHECK_EQ(42.0, the_number); |
| 1092 v8::Handle<v8::Value> new_boxed_number = v8::BoxedNumber::New(43); |
| 1093 CHECK(new_boxed_number->IsBoxedNumber()); |
| 1094 as_boxed = new_boxed_number.As<v8::BoxedNumber>(); |
| 1095 the_number = as_boxed->NumberValue(); |
| 1096 CHECK_EQ(43.0, the_number); |
| 1097 } |
| 1098 |
| 1099 |
| 1100 THREADED_TEST(BoxedBoolean) { |
| 1101 v8::HandleScope scope; |
| 1102 LocalContext env; |
| 1103 v8::Handle<Value> boxed_boolean = CompileRun("new Boolean(true)"); |
| 1104 CHECK(boxed_boolean->IsBoxedBoolean()); |
| 1105 v8::Handle<Value> unboxed_boolean = CompileRun("true"); |
| 1106 CHECK(!unboxed_boolean->IsBoxedBoolean()); |
| 1107 v8::Handle<Value> boxed_not_boolean = CompileRun("new Number(42)"); |
| 1108 CHECK(!boxed_not_boolean->IsBoxedBoolean()); |
| 1109 v8::Handle<v8::BoxedBoolean> as_boxed = boxed_boolean.As<v8::BoxedBoolean>(); |
| 1110 CHECK(!as_boxed.IsEmpty()); |
| 1111 bool the_boolean = as_boxed->BooleanValue(); |
| 1112 CHECK_EQ(true, the_boolean); |
| 1113 v8::Handle<v8::Value> boxed_true = v8::BoxedBoolean::New(true); |
| 1114 v8::Handle<v8::Value> boxed_false = v8::BoxedBoolean::New(false); |
| 1115 CHECK(boxed_true->IsBoxedBoolean()); |
| 1116 CHECK(boxed_false->IsBoxedBoolean()); |
| 1117 as_boxed = boxed_true.As<v8::BoxedBoolean>(); |
| 1118 CHECK_EQ(true, as_boxed->BooleanValue()); |
| 1119 as_boxed = boxed_false.As<v8::BoxedBoolean>(); |
| 1120 CHECK_EQ(false, as_boxed->BooleanValue()); |
| 1121 } |
| 1122 |
| 1123 |
1029 THREADED_TEST(Number) { | 1124 THREADED_TEST(Number) { |
1030 v8::HandleScope scope; | 1125 v8::HandleScope scope; |
1031 LocalContext env; | 1126 LocalContext env; |
1032 double PI = 3.1415926; | 1127 double PI = 3.1415926; |
1033 Local<v8::Number> pi_obj = v8::Number::New(PI); | 1128 Local<v8::Number> pi_obj = v8::Number::New(PI); |
1034 CHECK_EQ(PI, pi_obj->NumberValue()); | 1129 CHECK_EQ(PI, pi_obj->NumberValue()); |
1035 } | 1130 } |
1036 | 1131 |
1037 | 1132 |
1038 THREADED_TEST(ToNumber) { | 1133 THREADED_TEST(ToNumber) { |
(...skipping 13640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14679 } | 14774 } |
14680 | 14775 |
14681 i::Isolate::Current()->heap()->CollectAllGarbage(true); | 14776 i::Isolate::Current()->heap()->CollectAllGarbage(true); |
14682 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); | 14777 { i::Object* raw_map_cache = i::Isolate::Current()->context()->map_cache(); |
14683 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { | 14778 if (raw_map_cache != i::Isolate::Current()->heap()->undefined_value()) { |
14684 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); | 14779 i::MapCache* map_cache = i::MapCache::cast(raw_map_cache); |
14685 CHECK_GT(elements, map_cache->NumberOfElements()); | 14780 CHECK_GT(elements, map_cache->NumberOfElements()); |
14686 } | 14781 } |
14687 } | 14782 } |
14688 } | 14783 } |
OLD | NEW |