41 using namespace v8::internal;
54 static const char* kSource;
58 const char* PrintExtension::kSource =
"native function print();";
68 for (
int i = 0; i < args.
Length(); i++) {
69 if (i != 0) printf(
" ");
84 static void InitializeVM() {
87 const char* extensions[] = {
"v8/print",
"v8/gc" };
96 static MaybeObject* GetGlobalProperty(
const char* name) {
98 return Isolate::Current()->context()->global_object()->GetProperty(*symbol);
102 static void SetGlobalProperty(
const char* name,
Object* value) {
122 return FACTORY->NewFunctionFromSharedFunctionInfo(shared_function,
123 Isolate::Current()->native_context());
127 static double Inc(
int x) {
128 const char* source =
"result = %d + 1;";
135 bool has_pending_exception;
138 CHECK(!has_pending_exception);
139 return GetGlobalProperty(
"result")->ToObjectChecked()->Number();
150 static double Add(
int x,
int y) {
156 bool has_pending_exception;
159 CHECK(!has_pending_exception);
160 return GetGlobalProperty(
"result")->ToObjectChecked()->Number();
171 static double Abs(
int x) {
176 bool has_pending_exception;
179 CHECK(!has_pending_exception);
180 return GetGlobalProperty(
"result")->ToObjectChecked()->Number();
191 static double Sum(
int n) {
193 Compile(
"s = 0; while (n > 0) { s += n; n -= 1; }; result = s;");
197 bool has_pending_exception;
200 CHECK(!has_pending_exception);
201 return GetGlobalProperty(
"result")->ToObjectChecked()->Number();
215 const char* source =
"for (n = 0; n < 100; ++n) print(n, 1, 2);";
218 bool has_pending_exception;
221 CHECK(!has_pending_exception);
233 "if (a == a) r+=1;\n"
234 "if (a != new Object()) r+=2;\n"
236 "if (a.x == 42) r+=4;\n"
237 "function foo() { var x = 87; return x; }\n"
238 "if (foo() == 87) r+=8;\n"
239 "function bar() { var x; x = 99; return x; }\n"
240 "if (bar() == 99) r+=16;\n"
241 "function baz() { var x = 1, y, z = 2; y = 3; return x + y + z; }\n"
242 "if (baz() == 6) r+=32;\n"
243 "function Cons0() { this.x = 42; this.y = 87; }\n"
244 "if (new Cons0().x == 42) r+=64;\n"
245 "if (new Cons0().y == 87) r+=128;\n"
246 "function Cons2(x, y) { this.sum = x + y; }\n"
247 "if (new Cons2(3,4).sum == 7) r+=256;";
251 bool has_pending_exception;
254 CHECK(!has_pending_exception);
255 CHECK_EQ(511.0, GetGlobalProperty(
"r")->ToObjectChecked()->Number());
263 const char* source =
"throw 42;";
266 bool has_pending_exception;
269 CHECK(has_pending_exception);
270 CHECK_EQ(42.0, Isolate::Current()->pending_exception()->
271 ToObjectChecked()->Number());
285 const char* source =
"function foo(a) { gc(), print(a); }";
291 bool has_pending_exception;
294 CHECK(!has_pending_exception);
296 Object* foo_symbol =
FACTORY->LookupAsciiSymbol(
"foo")->ToObjectChecked();
297 MaybeObject* fun1_object = Isolate::Current()->context()->global_object()->
300 CHECK(fun1->IsJSFunction());
307 &has_pending_exception);
308 CHECK(!has_pending_exception);
319 script->set_source(
HEAP->undefined_value());
330 const char function_f[] =
"function f() {}";
331 const int max_rows = 1000;
332 const int buffer_size = max_rows +
sizeof(function_f);
334 memset(buffer.start(),
'\n', buffer_size - 1);
335 buffer[buffer_size - 1] =
'\0';
337 for (
int i = 0; i < max_rows; ++i) {
339 buffer[i - 1] =
'\n';
340 memcpy(&buffer[i], function_f,
sizeof(function_f) - 1);
355 if (!FLAG_cache_optimized_code)
return;
356 FLAG_allow_natives_syntax =
true;
359 for (
int i = 0; i < 10; i++) {
362 CompileRun(
"function MakeClosure() {"
363 " return function() { return x; };"
365 "var closure0 = MakeClosure();"
366 "%DebugPrint(closure0());"
367 "%OptimizeFunctionOnNextCall(closure0);"
368 "%DebugPrint(closure0());"
369 "var closure1 = MakeClosure();"
370 "var closure2 = MakeClosure();");
375 CHECK(fun1->IsOptimized() || !fun1->IsOptimizable());
376 CHECK(fun2->IsOptimized() || !fun2->IsOptimizable());
377 CHECK_EQ(fun1->code(), fun2->code());
382 #ifdef ENABLE_DISASSEMBLER
384 const char* property_name) {
387 return v8::Utils::OpenHandle(*fun);
396 if (f->code()->kind() == Code::FUNCTION) {
397 Address pc = f->code()->instruction_start();
399 Min(f->code()->instruction_size(),
400 static_cast<int>(f->code()->stack_check_table_offset()));
401 Address end = pc + decode_size;
406 OS::SNPrintF(smi_hex_buffer,
"0x%lx", reinterpret_cast<intptr_t>(smi));
408 int num_const = d.ConstantPoolSizeAt(pc);
409 if (num_const >= 0) {
412 pc += d.InstructionDecode(decode_buffer, pc);
420 TEST(SplitConstantsInFullCompiler) {
424 CompileRun(
"function f() { a = 12345678 }; f();");
425 CheckCodeForUnsafeLiteral(GetJSFunction(env->
Global(),
"f"));
426 CompileRun(
"function f(x) { a = 12345678 + x}; f(1);");
427 CheckCodeForUnsafeLiteral(GetJSFunction(env->
Global(),
"f"));
428 CompileRun(
"function f(x) { var arguments = 1; x += 12345678}; f(1);");
429 CheckCodeForUnsafeLiteral(GetJSFunction(env->
Global(),
"f"));
430 CompileRun(
"function f(x) { var arguments = 1; x = 12345678}; f(1);");
431 CheckCodeForUnsafeLiteral(GetJSFunction(env->
Global(),
"f"));
static Local< Script > Compile(Handle< String > source, ScriptOrigin *origin=NULL, ScriptData *pre_data=NULL, Handle< String > script_data=Handle< String >())
#define CHECK_EQ(expected, value)
static Local< FunctionTemplate > New(InvocationCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >())
static String * cast(Object *obj)
V8EXPORT Local< Value > Get(Handle< Value > key)
static Smi * FromInt(int value)
static V8EXPORT Local< String > New(const char *data, int length=-1)
v8::Handle< v8::Value > Print(const v8::Arguments &args)
Handle< Object > GetProperty(Handle< JSReceiver > obj, const char *name)
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunction(v8::Handle< v8::String > name)
Handle< Object > SetProperty(Handle< Object > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attributes, StrictModeFlag strict_mode)
static Handle< Object > Call(Handle< Object > callable, Handle< Object > receiver, int argc, Handle< Object > argv[], bool *pending_exception, bool convert_receiver=false)
Vector< const char > CStrVector(const char *data)
static Local< T > Cast(Local< S > that)
static int SNPrintF(Vector< char > str, const char *format,...)
int GetScriptLineNumber(Handle< Script > script, int code_pos)
static Handle< SharedFunctionInfo > Compile(Handle< String > source, Handle< Object > script_name, int line_offset, int column_offset, Handle< Context > context, v8::Extension *extension, ScriptDataImpl *pre_data, Handle< Object > script_data, NativesFlag is_natives_code)
static V8EXPORT Local< Integer > New(int32_t value)
V8EXPORT int GetScriptLineNumber() const
Handle< Primitive > V8EXPORT Undefined()
static v8::Handle< v8::Value > Print(const v8::Arguments &args)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
static Persistent< Context > New(ExtensionConfiguration *extensions=NULL, Handle< ObjectTemplate > global_template=Handle< ObjectTemplate >(), Handle< Value > global_object=Handle< Value >())