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

Side by Side Diff: test/cctest/test-api.cc

Issue 6929008: Make Date and RegExp inherit from Object in the API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/api.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_obj = v8::Date::New(PI); 1053 Local<Value> date = v8::Date::New(PI);
1054 CHECK_EQ(3.0, date_obj->NumberValue()); 1054 CHECK_EQ(3.0, date->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());
1055 } 1057 }
1056 1058
1057 1059
1058 THREADED_TEST(Boolean) { 1060 THREADED_TEST(Boolean) {
1059 v8::HandleScope scope; 1061 v8::HandleScope scope;
1060 LocalContext env; 1062 LocalContext env;
1061 v8::Handle<v8::Boolean> t = v8::True(); 1063 v8::Handle<v8::Boolean> t = v8::True();
1062 CHECK(t->Value()); 1064 CHECK(t->Value());
1063 v8::Handle<v8::Boolean> f = v8::False(); 1065 v8::Handle<v8::Boolean> f = v8::False();
1064 CHECK(!f->Value()); 1066 CHECK(!f->Value());
(...skipping 12668 matching lines...) Expand 10 before | Expand all | Expand 10 after
13733 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase | 13735 static_cast<v8::RegExp::Flags>(v8::RegExp::kIgnoreCase |
13734 v8::RegExp::kMultiline)); 13736 v8::RegExp::kMultiline));
13735 CHECK(re->IsRegExp()); 13737 CHECK(re->IsRegExp());
13736 CHECK(re->GetSource()->Equals(v8_str("foobarbaz"))); 13738 CHECK(re->GetSource()->Equals(v8_str("foobarbaz")));
13737 CHECK_EQ(static_cast<int>(re->GetFlags()), 13739 CHECK_EQ(static_cast<int>(re->GetFlags()),
13738 v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline); 13740 v8::RegExp::kIgnoreCase | v8::RegExp::kMultiline);
13739 13741
13740 context->Global()->Set(v8_str("re"), re); 13742 context->Global()->Set(v8_str("re"), re);
13741 ExpectTrue("re.test('FoobarbaZ')"); 13743 ExpectTrue("re.test('FoobarbaZ')");
13742 13744
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
13743 v8::TryCatch try_catch; 13750 v8::TryCatch try_catch;
13744 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); 13751 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone);
13745 CHECK(re.IsEmpty()); 13752 CHECK(re.IsEmpty());
13746 CHECK(try_catch.HasCaught()); 13753 CHECK(try_catch.HasCaught());
13747 context->Global()->Set(v8_str("ex"), try_catch.Exception()); 13754 context->Global()->Set(v8_str("ex"), try_catch.Exception());
13748 ExpectTrue("ex instanceof SyntaxError"); 13755 ExpectTrue("ex instanceof SyntaxError");
13749 } 13756 }
13750 13757
13751 13758
13752 THREADED_TEST(Equals) { 13759 THREADED_TEST(Equals) {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
14090 14097
14091 // Disallow but setting a global callback that will allow the calls. 14098 // Disallow but setting a global callback that will allow the calls.
14092 context->AllowCodeGenerationFromStrings(false); 14099 context->AllowCodeGenerationFromStrings(false);
14093 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed); 14100 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationAllowed);
14094 CheckCodeGenerationAllowed(); 14101 CheckCodeGenerationAllowed();
14095 14102
14096 // Set a callback that disallows the code generation. 14103 // Set a callback that disallows the code generation.
14097 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed); 14104 V8::SetAllowCodeGenerationFromStringsCallback(&CodeGenerationDisallowed);
14098 CheckCodeGenerationDisallowed(); 14105 CheckCodeGenerationDisallowed();
14099 } 14106 }
OLDNEW
« no previous file with comments | « src/api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698