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

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

Issue 15038002: Revert "deprecate Context::New which returns Persistent" (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
42 44
43 void SetSeeds(Handle<ByteArray> seeds, uint32_t state0, uint32_t state1) { 45 void SetSeeds(Handle<ByteArray> seeds, uint32_t state0, uint32_t state1) {
44 for (int i = 0; i < 4; i++) { 46 for (int i = 0; i < 4; i++) {
45 seeds->set(i, static_cast<byte>(state0 >> (i * kBitsPerByte))); 47 seeds->set(i, static_cast<byte>(state0 >> (i * kBitsPerByte)));
46 seeds->set(i + 4, static_cast<byte>(state1 >> (i * kBitsPerByte))); 48 seeds->set(i + 4, static_cast<byte>(state1 >> (i * kBitsPerByte)));
47 } 49 }
48 } 50 }
49 51
50 52
51 void TestSeeds(Handle<JSFunction> fun, 53 void TestSeeds(Handle<JSFunction> fun,
(...skipping 12 matching lines...) Expand all
64 double crankshaft_value = HeapNumber::cast(*value)->value(); 66 double crankshaft_value = HeapNumber::cast(*value)->value();
65 67
66 SetSeeds(seeds, state0, state1); 68 SetSeeds(seeds, state0, state1);
67 V8::FillHeapNumberWithRandom(*value, *context); 69 V8::FillHeapNumberWithRandom(*value, *context);
68 double runtime_value = HeapNumber::cast(*value)->value(); 70 double runtime_value = HeapNumber::cast(*value)->value();
69 CHECK_EQ(runtime_value, crankshaft_value); 71 CHECK_EQ(runtime_value, crankshaft_value);
70 } 72 }
71 73
72 74
73 TEST(CrankshaftRandom) { 75 TEST(CrankshaftRandom) {
74 v8::V8::Initialize(); 76 if (env.IsEmpty()) env = v8::Context::New();
75 // Skip test if crankshaft is disabled. 77 // Skip test if crankshaft is disabled.
76 if (!V8::UseCrankshaft()) return; 78 if (!V8::UseCrankshaft()) return;
77 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 79 v8::HandleScope scope(env->GetIsolate());
78 v8::HandleScope scope(isolate); 80 env->Enter();
79 v8::Context::Scope context_scope(v8::Context::New(isolate));
80 81
81 Handle<Context> context(Isolate::Current()->context()); 82 Handle<Context> context(Isolate::Current()->context());
82 Handle<JSObject> global(context->global_object()); 83 Handle<JSObject> global(context->global_object());
83 Handle<ByteArray> seeds(context->random_seed()); 84 Handle<ByteArray> seeds(context->random_seed());
84 bool has_pending_exception; 85 bool has_pending_exception;
85 86
86 CompileRun("function f() { return Math.random(); }"); 87 CompileRun("function f() { return Math.random(); }");
87 88
88 Object* string = FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("f"))-> 89 Object* string = FACTORY->InternalizeOneByteString(STATIC_ASCII_VECTOR("f"))->
89 ToObjectChecked(); 90 ToObjectChecked();
(...skipping 13 matching lines...) Expand all
103 104
104 // Test that we bail out to runtime when seeds are uninitialized (zeros). 105 // Test that we bail out to runtime when seeds are uninitialized (zeros).
105 SetSeeds(seeds, 0, 0); 106 SetSeeds(seeds, 0, 0);
106 Handle<Object> value = 107 Handle<Object> value =
107 Execution::Call(fun, global, 0, NULL, &has_pending_exception); 108 Execution::Call(fun, global, 0, NULL, &has_pending_exception);
108 CHECK(value->IsHeapNumber()); 109 CHECK(value->IsHeapNumber());
109 CHECK(fun->IsOptimized()); 110 CHECK(fun->IsOptimized());
110 double crankshaft_value = HeapNumber::cast(*value)->value(); 111 double crankshaft_value = HeapNumber::cast(*value)->value();
111 CHECK_NE(0.0, crankshaft_value); 112 CHECK_NE(0.0, crankshaft_value);
112 } 113 }
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