| OLD | NEW |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 V8::FillHeapNumberWithRandom(*value, *context); | 63 V8::FillHeapNumberWithRandom(*value, *context); |
| 64 double runtime_value = HeapNumber::cast(*value)->value(); | 64 double runtime_value = HeapNumber::cast(*value)->value(); |
| 65 CHECK_EQ(runtime_value, crankshaft_value); | 65 CHECK_EQ(runtime_value, crankshaft_value); |
| 66 } | 66 } |
| 67 | 67 |
| 68 | 68 |
| 69 TEST(CrankshaftRandom) { | 69 TEST(CrankshaftRandom) { |
| 70 v8::V8::Initialize(); | 70 v8::V8::Initialize(); |
| 71 // Skip test if crankshaft is disabled. | 71 // Skip test if crankshaft is disabled. |
| 72 if (!Isolate::Current()->use_crankshaft()) return; | 72 if (!Isolate::Current()->use_crankshaft()) return; |
| 73 v8::Isolate* v8_isolate = v8::Isolate::GetCurrent(); | 73 v8::Isolate* v8_isolate = CcTest::isolate(); |
| 74 v8::HandleScope scope(v8_isolate); | 74 v8::HandleScope scope(v8_isolate); |
| 75 v8::Context::Scope context_scope(v8::Context::New(v8_isolate)); | 75 v8::Context::Scope context_scope(v8::Context::New(v8_isolate)); |
| 76 | 76 |
| 77 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); | 77 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); |
| 78 Handle<Context> context(isolate->context()); | 78 Handle<Context> context(isolate->context()); |
| 79 Handle<JSObject> global(context->global_object()); | 79 Handle<JSObject> global(context->global_object()); |
| 80 Handle<ByteArray> seeds(context->random_seed()); | 80 Handle<ByteArray> seeds(context->random_seed()); |
| 81 bool has_pending_exception; | 81 bool has_pending_exception; |
| 82 | 82 |
| 83 CompileRun("function f() { return Math.random(); }"); | 83 CompileRun("function f() { return Math.random(); }"); |
| 84 | 84 |
| 85 Object* string = Isolate::Current()->factory()->InternalizeOneByteString( | 85 Object* string = Isolate::Current()->factory()->InternalizeOneByteString( |
| 86 STATIC_ASCII_VECTOR("f"))->ToObjectChecked(); | 86 STATIC_ASCII_VECTOR("f"))->ToObjectChecked(); |
| 87 MaybeObject* fun_object = | 87 MaybeObject* fun_object = |
| 88 context->global_object()->GetProperty(String::cast(string)); | 88 context->global_object()->GetProperty(String::cast(string)); |
| 89 Handle<JSFunction> fun(JSFunction::cast(fun_object->ToObjectChecked())); | 89 Handle<JSFunction> fun(JSFunction::cast(fun_object->ToObjectChecked())); |
| 90 | 90 |
| 91 // Optimize function. | 91 // Optimize function. |
| 92 Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception); | 92 Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception); |
| 93 Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception); | 93 Execution::Call(isolate, fun, global, 0, NULL, &has_pending_exception); |
| 94 if (!fun->IsOptimized()) fun->MarkForLazyRecompilation(); | 94 if (!fun->IsOptimized()) fun->MarkForLazyRecompilation(); |
| 95 | 95 |
| 96 // Test with some random values. | 96 // Test with some random values. |
| 97 TestSeeds(fun, context, 0xC0C0AFFE, 0x31415926); | 97 TestSeeds(fun, context, 0xC0C0AFFE, 0x31415926); |
| 98 TestSeeds(fun, context, 0x01020304, 0xFFFFFFFF); | 98 TestSeeds(fun, context, 0x01020304, 0xFFFFFFFF); |
| 99 TestSeeds(fun, context, 0x00000001, 0x00000001); | 99 TestSeeds(fun, context, 0x00000001, 0x00000001); |
| 100 } | 100 } |
| OLD | NEW |