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

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

Issue 16337005: Deprecate FACTORY helper macro. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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 | « test/cctest/test-assembler-ia32.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 printf("\n"); 73 printf("\n");
74 return v8::Undefined(); 74 return v8::Undefined();
75 } 75 }
76 76
77 77
78 static PrintExtension kPrintExtension; 78 static PrintExtension kPrintExtension;
79 v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension); 79 v8::DeclareExtension kPrintExtensionDeclaration(&kPrintExtension);
80 80
81 81
82 static MaybeObject* GetGlobalProperty(const char* name) { 82 static MaybeObject* GetGlobalProperty(const char* name) {
83 Handle<String> internalized_name = FACTORY->InternalizeUtf8String(name); 83 Isolate* isolate = Isolate::Current();
84 return Isolate::Current()->context()->global_object()->GetProperty( 84 Handle<String> internalized_name =
85 *internalized_name); 85 isolate->factory()->InternalizeUtf8String(name);
86 return isolate->context()->global_object()->GetProperty(*internalized_name);
86 } 87 }
87 88
88 89
89 static void SetGlobalProperty(const char* name, Object* value) { 90 static void SetGlobalProperty(const char* name, Object* value) {
90 Isolate* isolate = Isolate::Current(); 91 Isolate* isolate = Isolate::Current();
91 Handle<Object> object(value, isolate); 92 Handle<Object> object(value, isolate);
92 Handle<String> internalized_name = 93 Handle<String> internalized_name =
93 isolate->factory()->InternalizeUtf8String(name); 94 isolate->factory()->InternalizeUtf8String(name);
94 Handle<JSObject> global(isolate->context()->global_object()); 95 Handle<JSObject> global(isolate->context()->global_object());
95 SetProperty(isolate, global, internalized_name, object, NONE, kNonStrictMode); 96 SetProperty(isolate, global, internalized_name, object, NONE, kNonStrictMode);
96 } 97 }
97 98
98 99
99 static Handle<JSFunction> Compile(const char* source) { 100 static Handle<JSFunction> Compile(const char* source) {
100 Handle<String> source_code(FACTORY->NewStringFromUtf8(CStrVector(source))); 101 Isolate* isolate = Isolate::Current();
102 Handle<String> source_code(
103 isolate->factory()->NewStringFromUtf8(CStrVector(source)));
101 Handle<SharedFunctionInfo> shared_function = 104 Handle<SharedFunctionInfo> shared_function =
102 Compiler::Compile(source_code, 105 Compiler::Compile(source_code,
103 Handle<String>(), 106 Handle<String>(),
104 0, 107 0,
105 0, 108 0,
106 Handle<Context>(Isolate::Current()->native_context()), 109 Handle<Context>(isolate->native_context()),
107 NULL, 110 NULL,
108 NULL, 111 NULL,
109 Handle<String>::null(), 112 Handle<String>::null(),
110 NOT_NATIVES_CODE); 113 NOT_NATIVES_CODE);
111 return FACTORY->NewFunctionFromSharedFunctionInfo(shared_function, 114 return isolate->factory()->NewFunctionFromSharedFunctionInfo(
112 Isolate::Current()->native_context()); 115 shared_function, isolate->native_context());
113 } 116 }
114 117
115 118
116 static double Inc(int x) { 119 static double Inc(int x) {
117 const char* source = "result = %d + 1;"; 120 const char* source = "result = %d + 1;";
118 EmbeddedVector<char, 512> buffer; 121 EmbeddedVector<char, 512> buffer;
119 OS::SNPrintF(buffer, source, x); 122 OS::SNPrintF(buffer, source, x);
120 123
121 Handle<JSFunction> fun = Compile(buffer.start()); 124 Handle<JSFunction> fun = Compile(buffer.start());
122 if (fun.is_null()) return -1; 125 if (fun.is_null()) return -1;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 Handle<JSFunction> fun0 = Compile(source); 279 Handle<JSFunction> fun0 = Compile(source);
277 CHECK(!fun0.is_null()); 280 CHECK(!fun0.is_null());
278 Isolate* isolate = fun0->GetIsolate(); 281 Isolate* isolate = fun0->GetIsolate();
279 282
280 // Run the generated code to populate the global object with 'foo'. 283 // Run the generated code to populate the global object with 'foo'.
281 bool has_pending_exception; 284 bool has_pending_exception;
282 Handle<JSObject> global(Isolate::Current()->context()->global_object()); 285 Handle<JSObject> global(Isolate::Current()->context()->global_object());
283 Execution::Call(fun0, global, 0, NULL, &has_pending_exception); 286 Execution::Call(fun0, global, 0, NULL, &has_pending_exception);
284 CHECK(!has_pending_exception); 287 CHECK(!has_pending_exception);
285 288
286 Object* foo_string = 289 Object* foo_string = isolate->factory()->InternalizeOneByteString(
287 FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("foo"))-> 290 STATIC_ASCII_VECTOR("foo"))->ToObjectChecked();
288 ToObjectChecked();
289 MaybeObject* fun1_object = isolate->context()->global_object()-> 291 MaybeObject* fun1_object = isolate->context()->global_object()->
290 GetProperty(String::cast(foo_string)); 292 GetProperty(String::cast(foo_string));
291 Handle<Object> fun1(fun1_object->ToObjectChecked(), isolate); 293 Handle<Object> fun1(fun1_object->ToObjectChecked(), isolate);
292 CHECK(fun1->IsJSFunction()); 294 CHECK(fun1->IsJSFunction());
293 295
294 Handle<Object> argv[] = 296 Handle<Object> argv[] = { isolate->factory()->InternalizeOneByteString(
295 { FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("hello")) }; 297 STATIC_ASCII_VECTOR("hello")) };
296 Execution::Call(Handle<JSFunction>::cast(fun1), 298 Execution::Call(Handle<JSFunction>::cast(fun1),
297 global, 299 global,
298 ARRAY_SIZE(argv), 300 ARRAY_SIZE(argv),
299 argv, 301 argv,
300 &has_pending_exception); 302 &has_pending_exception);
301 CHECK(!has_pending_exception); 303 CHECK(!has_pending_exception);
302 } 304 }
303 305
304 306
305 // Regression 236. Calling InitLineEnds on a Script with undefined 307 // Regression 236. Calling InitLineEnds on a Script with undefined
306 // source resulted in crash. 308 // source resulted in crash.
307 TEST(Regression236) { 309 TEST(Regression236) {
308 CcTest::InitializeVM(); 310 CcTest::InitializeVM();
311 Isolate* isolate = Isolate::Current();
312 Factory* factory = isolate->factory();
309 v8::HandleScope scope(CcTest::isolate()); 313 v8::HandleScope scope(CcTest::isolate());
310 314
311 Handle<Script> script = FACTORY->NewScript(FACTORY->empty_string()); 315 Handle<Script> script = factory->NewScript(factory->empty_string());
312 script->set_source(HEAP->undefined_value()); 316 script->set_source(HEAP->undefined_value());
313 CHECK_EQ(-1, GetScriptLineNumber(script, 0)); 317 CHECK_EQ(-1, GetScriptLineNumber(script, 0));
314 CHECK_EQ(-1, GetScriptLineNumber(script, 100)); 318 CHECK_EQ(-1, GetScriptLineNumber(script, 100));
315 CHECK_EQ(-1, GetScriptLineNumber(script, -1)); 319 CHECK_EQ(-1, GetScriptLineNumber(script, -1));
316 } 320 }
317 321
318 322
319 TEST(GetScriptLineNumber) { 323 TEST(GetScriptLineNumber) {
320 CcTest::InitializeVM(); 324 CcTest::InitializeVM();
321 v8::HandleScope scope(CcTest::isolate()); 325 v8::HandleScope scope(CcTest::isolate());
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 CompileRun("function f() { a = 12345678 }; f();"); 421 CompileRun("function f() { a = 12345678 }; f();");
418 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); 422 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f"));
419 CompileRun("function f(x) { a = 12345678 + x}; f(1);"); 423 CompileRun("function f(x) { a = 12345678 + x}; f(1);");
420 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); 424 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f"));
421 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);"); 425 CompileRun("function f(x) { var arguments = 1; x += 12345678}; f(1);");
422 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); 426 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f"));
423 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);"); 427 CompileRun("function f(x) { var arguments = 1; x = 12345678}; f(1);");
424 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f")); 428 CheckCodeForUnsafeLiteral(GetJSFunction(CcTest::env()->Global(), "f"));
425 } 429 }
426 #endif 430 #endif
OLDNEW
« no previous file with comments | « test/cctest/test-assembler-ia32.cc ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698