Chromium Code Reviews| 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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 | 807 |
| 808 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); | 808 Local<Value> result = v8_compile("(new obj()).toString()")->Run(); |
| 809 CHECK_EQ(v8_str("[object funky]"), result); | 809 CHECK_EQ(v8_str("[object funky]"), result); |
| 810 | 810 |
| 811 result = v8_compile("(new obj()).m")->Run(); | 811 result = v8_compile("(new obj()).m")->Run(); |
| 812 CHECK_EQ(239, result->Int32Value()); | 812 CHECK_EQ(239, result->Int32Value()); |
| 813 } | 813 } |
| 814 } | 814 } |
| 815 | 815 |
| 816 | 816 |
| 817 static v8::Handle<v8::Value> callback(const v8::Arguments& args) { | |
| 818 int* value = reinterpret_cast<int*>(v8::External::Unwrap(args.Data())); | |
| 819 CHECK_EQ(42, *value); | |
| 820 return v8::Integer::New(*value); | |
| 821 } | |
| 822 | |
| 823 | |
| 824 THREADED_TEST(PointerAsData) { | |
| 825 v8::HandleScope scope; | |
| 826 LocalContext env; | |
| 827 | |
| 828 int* value = new int; | |
| 829 *value = 42; | |
|
Lasse Reichstein
2011/01/13 12:57:57
Try storing both values that can and can't be stor
antonm
2011/01/13 15:49:15
Done.
| |
| 830 v8::Handle<v8::Value> data = v8::External::Wrap(value); | |
| 831 | |
| 832 v8::Handle<v8::Object> obj = v8::Object::New(); | |
| 833 obj->Set(v8_str("func"), | |
| 834 v8::FunctionTemplate::New(callback, data)->GetFunction()); | |
| 835 env->Global()->Set(v8_str("obj"), obj); | |
| 836 | |
| 837 CHECK(CompileRun( | |
| 838 "function foo() {\n" | |
| 839 " for (var i = 0; i < 13; i++) {\n" | |
| 840 " if (42 != obj.func()) throw 'oops';\n" | |
| 841 " }\n" | |
| 842 " return true;\n" | |
| 843 "}\n" | |
| 844 "foo(), true")->BooleanValue()); | |
| 845 | |
| 846 delete value; | |
| 847 } | |
| 848 | |
| 849 | |
| 817 THREADED_TEST(FindInstanceInPrototypeChain) { | 850 THREADED_TEST(FindInstanceInPrototypeChain) { |
| 818 v8::HandleScope scope; | 851 v8::HandleScope scope; |
| 819 LocalContext env; | 852 LocalContext env; |
| 820 | 853 |
| 821 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); | 854 Local<v8::FunctionTemplate> base = v8::FunctionTemplate::New(); |
| 822 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); | 855 Local<v8::FunctionTemplate> derived = v8::FunctionTemplate::New(); |
| 823 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); | 856 Local<v8::FunctionTemplate> other = v8::FunctionTemplate::New(); |
| 824 derived->Inherit(base); | 857 derived->Inherit(base); |
| 825 | 858 |
| 826 Local<v8::Function> base_function = base->GetFunction(); | 859 Local<v8::Function> base_function = base->GetFunction(); |
| (...skipping 11246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12073 v8::Context::Scope context_scope(context.local()); | 12106 v8::Context::Scope context_scope(context.local()); |
| 12074 | 12107 |
| 12075 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); | 12108 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); |
| 12076 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); | 12109 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); |
| 12077 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); | 12110 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); |
| 12078 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( | 12111 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( |
| 12079 "var result = []; for (var k in o) result.push(k); result")); | 12112 "var result = []; for (var k in o) result.push(k); result")); |
| 12080 CHECK_EQ(1, result->Length()); | 12113 CHECK_EQ(1, result->Length()); |
| 12081 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); | 12114 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); |
| 12082 } | 12115 } |
| OLD | NEW |