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

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

Issue 14947005: fix nosnapshot test failure in 14793004, do not deprecate function (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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-profile-generator.cc ('k') | test/cctest/test-regexp.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 21 matching lines...) Expand all
32 #include "v8.h" 32 #include "v8.h"
33 33
34 #include "cctest.h" 34 #include "cctest.h"
35 #include "compiler.h" 35 #include "compiler.h"
36 #include "execution.h" 36 #include "execution.h"
37 #include "isolate.h" 37 #include "isolate.h"
38 38
39 39
40 using namespace v8::internal; 40 using namespace v8::internal;
41 41
42 static v8::Persistent<v8::Context> env;
43
44 42
45 void SetSeeds(Handle<ByteArray> seeds, uint32_t state0, uint32_t state1) { 43 void SetSeeds(Handle<ByteArray> seeds, uint32_t state0, uint32_t state1) {
46 for (int i = 0; i < 4; i++) { 44 for (int i = 0; i < 4; i++) {
47 seeds->set(i, static_cast<byte>(state0 >> (i * kBitsPerByte))); 45 seeds->set(i, static_cast<byte>(state0 >> (i * kBitsPerByte)));
48 seeds->set(i + 4, static_cast<byte>(state1 >> (i * kBitsPerByte))); 46 seeds->set(i + 4, static_cast<byte>(state1 >> (i * kBitsPerByte)));
49 } 47 }
50 } 48 }
51 49
52 50
53 void TestSeeds(Handle<JSFunction> fun, 51 void TestSeeds(Handle<JSFunction> fun,
(...skipping 12 matching lines...) Expand all
66 double crankshaft_value = HeapNumber::cast(*value)->value(); 64 double crankshaft_value = HeapNumber::cast(*value)->value();
67 65
68 SetSeeds(seeds, state0, state1); 66 SetSeeds(seeds, state0, state1);
69 V8::FillHeapNumberWithRandom(*value, *context); 67 V8::FillHeapNumberWithRandom(*value, *context);
70 double runtime_value = HeapNumber::cast(*value)->value(); 68 double runtime_value = HeapNumber::cast(*value)->value();
71 CHECK_EQ(runtime_value, crankshaft_value); 69 CHECK_EQ(runtime_value, crankshaft_value);
72 } 70 }
73 71
74 72
75 TEST(CrankshaftRandom) { 73 TEST(CrankshaftRandom) {
76 if (env.IsEmpty()) env = v8::Context::New(); 74 v8::V8::Initialize();
77 // Skip test if crankshaft is disabled. 75 // Skip test if crankshaft is disabled.
78 if (!V8::UseCrankshaft()) return; 76 if (!V8::UseCrankshaft()) return;
79 v8::HandleScope scope(env->GetIsolate()); 77 v8::Isolate* isolate = v8::Isolate::GetCurrent();
80 env->Enter(); 78 v8::HandleScope scope(isolate);
79 v8::Context::Scope context_scope(v8::Context::New(isolate));
81 80
82 Handle<Context> context(Isolate::Current()->context()); 81 Handle<Context> context(Isolate::Current()->context());
83 Handle<JSObject> global(context->global_object()); 82 Handle<JSObject> global(context->global_object());
84 Handle<ByteArray> seeds(context->random_seed()); 83 Handle<ByteArray> seeds(context->random_seed());
85 bool has_pending_exception; 84 bool has_pending_exception;
86 85
87 CompileRun("function f() { return Math.random(); }"); 86 CompileRun("function f() { return Math.random(); }");
88 87
89 Object* string = FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("f"))-> 88 Object* string = FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("f"))->
90 ToObjectChecked(); 89 ToObjectChecked();
(...skipping 13 matching lines...) Expand all
104 103
105 // Test that we bail out to runtime when seeds are uninitialized (zeros). 104 // Test that we bail out to runtime when seeds are uninitialized (zeros).
106 SetSeeds(seeds, 0, 0); 105 SetSeeds(seeds, 0, 0);
107 Handle<Object> value = 106 Handle<Object> value =
108 Execution::Call(fun, global, 0, NULL, &has_pending_exception); 107 Execution::Call(fun, global, 0, NULL, &has_pending_exception);
109 CHECK(value->IsHeapNumber()); 108 CHECK(value->IsHeapNumber());
110 CHECK(fun->IsOptimized()); 109 CHECK(fun->IsOptimized());
111 double crankshaft_value = HeapNumber::cast(*value)->value(); 110 double crankshaft_value = HeapNumber::cast(*value)->value();
112 CHECK_NE(0.0, crankshaft_value); 111 CHECK_NE(0.0, crankshaft_value);
113 } 112 }
OLDNEW
« no previous file with comments | « test/cctest/test-profile-generator.cc ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698