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

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

Issue 551063: Fixed issue 582: set the right construct stub for native functions. (Closed)
Patch Set: Created 10 years, 11 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
« no previous file with comments | « src/parser.cc ('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 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 2770 matching lines...) Expand 10 before | Expand all | Expand 10 after
2781 "native function C();" 2781 "native function C();"
2782 "function Foo(i) {" 2782 "function Foo(i) {"
2783 " if (i == 0) return A();" 2783 " if (i == 0) return A();"
2784 " if (i == 1) return B();" 2784 " if (i == 1) return B();"
2785 " if (i == 2) return C();" 2785 " if (i == 2) return C();"
2786 "}"; 2786 "}";
2787 2787
2788 2788
2789 static v8::Handle<Value> CallFun(const v8::Arguments& args) { 2789 static v8::Handle<Value> CallFun(const v8::Arguments& args) {
2790 ApiTestFuzzer::Fuzz(); 2790 ApiTestFuzzer::Fuzz();
2791 if (args.IsConstructCall()) {
2792 args.This()->Set(v8_str("data"), args.Data());
2793 }
2791 return args.Data(); 2794 return args.Data();
2792 } 2795 }
2793 2796
2794 2797
2795 class FunctionExtension : public Extension { 2798 class FunctionExtension : public Extension {
2796 public: 2799 public:
2797 FunctionExtension() : Extension("functiontest", kExtensionTestScript) { } 2800 FunctionExtension() : Extension("functiontest", kExtensionTestScript) { }
2798 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 2801 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
2799 v8::Handle<String> name); 2802 v8::Handle<String> name);
2800 }; 2803 };
(...skipping 21 matching lines...) Expand all
2822 static const char* exts[1] = { "functiontest" }; 2825 static const char* exts[1] = { "functiontest" };
2823 v8::ExtensionConfiguration config(1, exts); 2826 v8::ExtensionConfiguration config(1, exts);
2824 LocalContext context(&config); 2827 LocalContext context(&config);
2825 CHECK_EQ(3, lookup_count); 2828 CHECK_EQ(3, lookup_count);
2826 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run()); 2829 CHECK_EQ(v8::Integer::New(8), Script::Compile(v8_str("Foo(0)"))->Run());
2827 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run()); 2830 CHECK_EQ(v8::Integer::New(7), Script::Compile(v8_str("Foo(1)"))->Run());
2828 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run()); 2831 CHECK_EQ(v8::Integer::New(6), Script::Compile(v8_str("Foo(2)"))->Run());
2829 } 2832 }
2830 2833
2831 2834
2835 THREADED_TEST(NativeFunctionConstructCall) {
2836 v8::RegisterExtension(new FunctionExtension());
2837 v8::HandleScope handle_scope;
2838 static const char* exts[1] = { "functiontest" };
2839 v8::ExtensionConfiguration config(1, exts);
2840 LocalContext context(&config);
2841 CHECK_EQ(v8::Integer::New(8),
2842 Script::Compile(v8_str("(new A()).data"))->Run());
2843 CHECK_EQ(v8::Integer::New(7),
2844 Script::Compile(v8_str("(new B()).data"))->Run());
2845 CHECK_EQ(v8::Integer::New(6),
2846 Script::Compile(v8_str("(new C()).data"))->Run());
2847 }
2848
2849
2832 static const char* last_location; 2850 static const char* last_location;
2833 static const char* last_message; 2851 static const char* last_message;
2834 void StoringErrorCallback(const char* location, const char* message) { 2852 void StoringErrorCallback(const char* location, const char* message) {
2835 if (last_location == NULL) { 2853 if (last_location == NULL) {
2836 last_location = location; 2854 last_location = location;
2837 last_message = message; 2855 last_message = message;
2838 } 2856 }
2839 } 2857 }
2840 2858
2841 2859
(...skipping 5817 matching lines...) Expand 10 before | Expand all | Expand 10 after
8659 CompileRun(source_exception); 8677 CompileRun(source_exception);
8660 other_context->Exit(); 8678 other_context->Exit();
8661 v8::internal::Heap::CollectAllGarbage(false); 8679 v8::internal::Heap::CollectAllGarbage(false);
8662 if (GetGlobalObjectsCount() == 1) break; 8680 if (GetGlobalObjectsCount() == 1) break;
8663 } 8681 }
8664 CHECK_GE(2, gc_count); 8682 CHECK_GE(2, gc_count);
8665 CHECK_EQ(1, GetGlobalObjectsCount()); 8683 CHECK_EQ(1, GetGlobalObjectsCount());
8666 8684
8667 other_context.Dispose(); 8685 other_context.Dispose();
8668 } 8686 }
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698