OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 11709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11720 context->Global()->Set(v8_str("re"), re); | 11720 context->Global()->Set(v8_str("re"), re); |
11721 ExpectTrue("re.test('FoobarbaZ')"); | 11721 ExpectTrue("re.test('FoobarbaZ')"); |
11722 | 11722 |
11723 v8::TryCatch try_catch; | 11723 v8::TryCatch try_catch; |
11724 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); | 11724 re = v8::RegExp::New(v8_str("foo["), v8::RegExp::kNone); |
11725 CHECK(re.IsEmpty()); | 11725 CHECK(re.IsEmpty()); |
11726 CHECK(try_catch.HasCaught()); | 11726 CHECK(try_catch.HasCaught()); |
11727 context->Global()->Set(v8_str("ex"), try_catch.Exception()); | 11727 context->Global()->Set(v8_str("ex"), try_catch.Exception()); |
11728 ExpectTrue("ex instanceof SyntaxError"); | 11728 ExpectTrue("ex instanceof SyntaxError"); |
11729 } | 11729 } |
| 11730 |
| 11731 |
| 11732 static v8::Handle<v8::Value> Getter(v8::Local<v8::String> property, |
| 11733 const v8::AccessorInfo& info ) { |
| 11734 return v8_str("42!"); |
| 11735 } |
| 11736 |
| 11737 |
| 11738 static v8::Handle<v8::Array> Enumerator(const v8::AccessorInfo& info) { |
| 11739 v8::Handle<v8::Array> result = v8::Array::New(); |
| 11740 result->Set(0, v8_str("universalAnswer")); |
| 11741 return result; |
| 11742 } |
| 11743 |
| 11744 |
| 11745 TEST(NamedEnumeratorAndForIn) { |
| 11746 v8::HandleScope handle_scope; |
| 11747 LocalContext context; |
| 11748 v8::Context::Scope context_scope(context.local()); |
| 11749 |
| 11750 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
| 11751 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
| 11752 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
| 11753 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
| 11754 "var result = []; for (var k in o) result.push(k); result")); |
| 11755 CHECK_EQ(1, result->Length()); |
| 11756 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
| 11757 } |
OLD | NEW |