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 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 CHECK_EQ(1.0, t->NumberValue()); | 1043 CHECK_EQ(1.0, t->NumberValue()); |
1044 v8::Handle<v8::Boolean> f = v8::False(); | 1044 v8::Handle<v8::Boolean> f = v8::False(); |
1045 CHECK_EQ(0.0, f->NumberValue()); | 1045 CHECK_EQ(0.0, f->NumberValue()); |
1046 } | 1046 } |
1047 | 1047 |
1048 | 1048 |
1049 THREADED_TEST(Date) { | 1049 THREADED_TEST(Date) { |
1050 v8::HandleScope scope; | 1050 v8::HandleScope scope; |
1051 LocalContext env; | 1051 LocalContext env; |
1052 double PI = 3.1415926; | 1052 double PI = 3.1415926; |
1053 Local<Value> date = v8::Date::New(PI); | 1053 Local<Value> date_obj = v8::Date::New(PI); |
1054 CHECK_EQ(3.0, date->NumberValue()); | 1054 CHECK_EQ(3.0, date_obj->NumberValue()); |
1055 date.As<v8::Date>()->Set(v8_str("property"), v8::Integer::New(42)); | |
1056 CHECK_EQ(42, date.As<v8::Date>()->Get(v8_str("property"))->Int32Value()); | |
1057 } | 1055 } |
1058 | 1056 |
1059 | 1057 |
1060 THREADED_TEST(Boolean) { | 1058 THREADED_TEST(Boolean) { |
1061 v8::HandleScope scope; | 1059 v8::HandleScope scope; |
1062 LocalContext env; | 1060 LocalContext env; |
1063 v8::Handle<v8::Boolean> t = v8::True(); | 1061 v8::Handle<v8::Boolean> t = v8::True(); |
1064 CHECK(t->Value()); | 1062 CHECK(t->Value()); |
1065 v8::Handle<v8::Boolean> f = v8::False(); | 1063 v8::Handle<v8::Boolean> f = v8::False(); |
1066 CHECK(!f->Value()); | 1064 CHECK(!f->Value()); |
(...skipping 12668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13735 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | | 13733 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | |
13736 v8::RegExp::kMultiline)); | 13734 v8::RegExp::kMultiline)); |
13737 CHECK(re->IsRegExp()); | 13735 CHECK(re->IsRegExp()); |
13738 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); | 13736 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); |
13739 CHECK_EQ(static_cast<int>(re->GetFlags()), | 13737 CHECK_EQ(static_cast<int>(re->GetFlags()), |
13740 v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline); | 13738 v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline); |
13741 | 13739 |
13742 context->Global()->Set(v8_str("re"), re); | 13740 context->Global()->Set(v8_str("re"), re); |
13743 ExpectTrue("re.test('FoobarbaZ')"); | 13741 ExpectTrue("re.test('FoobarbaZ')"); |
13744 | 13742 |
13745 // RegExps are objects on which you can set properties. | |
13746 re->Set(v8_str("property"), v8::Integer::New(32)); | |
13747 v8::Handle<v8::Value> value = CompileRun("re.property"); | |
13748 ASSERT_EQ(32, value->Int32Value()); | |
13749 | |
13750 v8::TryCatch try_catch; | 13743 v8::TryCatch try_catch; |
13751 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); | 13744 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); |
13752 CHECK(re.IsEmpty()); | 13745 CHECK(re.IsEmpty()); |
13753 CHECK(try_catch.HasCaught()); | 13746 CHECK(try_catch.HasCaught()); |
13754 context->Global()->Set(v8_str("ex"), try_catch.Exception()); | 13747 context->Global()->Set(v8_str("ex"), try_catch.Exception()); |
13755 ExpectTrue("ex instanceof SyntaxError"); | 13748 ExpectTrue("ex instanceof SyntaxError"); |
13756 } | 13749 } |
13757 | 13750 |
13758 | 13751 |
13759 THREADED_TEST(Equals) { | 13752 THREADED_TEST(Equals) { |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14097 | 14090 |
14098 // Disallow but setting a global callback that will allow the calls. | 14091 // Disallow but setting a global callback that will allow the calls. |
14099 context->AllowCodeGenerationFromStrings(false); | 14092 context->AllowCodeGenerationFromStrings(false); |
14100 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); | 14093 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); |
14101 CheckCodeGenerationAllowed(); | 14094 CheckCodeGenerationAllowed(); |
14102 | 14095 |
14103 // Set a callback that disallows the code generation. | 14096 // Set a callback that disallows the code generation. |
14104 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); | 14097 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); |
14105 CheckCodeGenerationDisallowed(); | 14098 CheckCodeGenerationDisallowed(); |
14106 } | 14099 } |
OLD | NEW |