OLD | NEW |
1 // Copyright 2007-2010 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2010 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 { | 455 { |
456 v8::HandleScope handle_scope(v8_isolate); | 456 v8::HandleScope handle_scope(v8_isolate); |
457 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); | 457 v8::Local<v8::Context>::New(v8_isolate, env)->Enter(); |
458 // After execution, e's function context refers to the global object. | 458 // After execution, e's function context refers to the global object. |
459 CompileRun( | 459 CompileRun( |
460 "var e;" | 460 "var e;" |
461 "(function() {" | 461 "(function() {" |
462 " e = function(s) { return eval (s); }" | 462 " e = function(s) { return eval (s); }" |
463 "})();" | 463 "})();" |
464 "var o = this;" | 464 "var o = this;" |
465 "var r = Math.sin(0) + Math.cos(0);" | 465 "var r = Math.random();" |
| 466 "var c = Math.sin(0) + Math.cos(0);" |
466 "var f = (function(a, b) { return a + b; }).bind(1, 2, 3);" | 467 "var f = (function(a, b) { return a + b; }).bind(1, 2, 3);" |
467 "var s = parseInt('12345');"); | 468 "var s = parseInt('12345');"); |
468 | 469 |
469 Vector<const uint8_t> source = ConstructSource( | 470 Vector<const uint8_t> source = ConstructSource( |
470 STATIC_CHAR_VECTOR("function g() { return [,"), | 471 STATIC_CHAR_VECTOR("function g() { return [,"), |
471 STATIC_CHAR_VECTOR("1,"), | 472 STATIC_CHAR_VECTOR("1,"), |
472 STATIC_CHAR_VECTOR("];} a = g(); b = g(); b.push(1);"), 100000); | 473 STATIC_CHAR_VECTOR("];} a = g(); b = g(); b.push(1);"), 100000); |
473 v8::MaybeLocal<v8::String> source_str = v8::String::NewFromOneByte( | 474 v8::MaybeLocal<v8::String> source_str = v8::String::NewFromOneByte( |
474 v8_isolate, source.start(), v8::NewStringType::kNormal, | 475 v8_isolate, source.start(), v8::NewStringType::kNormal, |
475 source.length()); | 476 source.length()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 Handle<JSObject> global_object(context->global_object(), isolate); | 552 Handle<JSObject> global_object(context->global_object(), isolate); |
552 Handle<Object> property = JSReceiver::GetDataProperty(global_object, o); | 553 Handle<Object> property = JSReceiver::GetDataProperty(global_object, o); |
553 CHECK(property.is_identical_to(global_proxy)); | 554 CHECK(property.is_identical_to(global_proxy)); |
554 | 555 |
555 v8::Local<v8::Context> v8_context = v8::Utils::ToLocal(context); | 556 v8::Local<v8::Context> v8_context = v8::Utils::ToLocal(context); |
556 v8::Context::Scope context_scope(v8_context); | 557 v8::Context::Scope context_scope(v8_context); |
557 double r = CompileRun("r") | 558 double r = CompileRun("r") |
558 ->ToNumber(v8_isolate->GetCurrentContext()) | 559 ->ToNumber(v8_isolate->GetCurrentContext()) |
559 .ToLocalChecked() | 560 .ToLocalChecked() |
560 ->Value(); | 561 ->Value(); |
561 CHECK_EQ(1, r); | 562 CHECK(0.0 <= r && r < 1.0); |
| 563 // Math.random still works. |
| 564 double random = CompileRun("Math.random()") |
| 565 ->ToNumber(v8_isolate->GetCurrentContext()) |
| 566 .ToLocalChecked() |
| 567 ->Value(); |
| 568 CHECK(0.0 <= random && random < 1.0); |
| 569 double c = CompileRun("c") |
| 570 ->ToNumber(v8_isolate->GetCurrentContext()) |
| 571 .ToLocalChecked() |
| 572 ->Value(); |
| 573 CHECK_EQ(1, c); |
562 int f = CompileRun("f()") | 574 int f = CompileRun("f()") |
563 ->ToNumber(v8_isolate->GetCurrentContext()) | 575 ->ToNumber(v8_isolate->GetCurrentContext()) |
564 .ToLocalChecked() | 576 .ToLocalChecked() |
565 ->Int32Value(v8_isolate->GetCurrentContext()) | 577 ->Int32Value(v8_isolate->GetCurrentContext()) |
566 .FromJust(); | 578 .FromJust(); |
567 CHECK_EQ(5, f); | 579 CHECK_EQ(5, f); |
568 f = CompileRun("e('f()')") | 580 f = CompileRun("e('f()')") |
569 ->ToNumber(v8_isolate->GetCurrentContext()) | 581 ->ToNumber(v8_isolate->GetCurrentContext()) |
570 .ToLocalChecked() | 582 .ToLocalChecked() |
571 ->Int32Value(v8_isolate->GetCurrentContext()) | 583 ->Int32Value(v8_isolate->GetCurrentContext()) |
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 delete script_data; | 1672 delete script_data; |
1661 } | 1673 } |
1662 | 1674 |
1663 | 1675 |
1664 TEST(SerializationMemoryStats) { | 1676 TEST(SerializationMemoryStats) { |
1665 FLAG_profile_deserialization = true; | 1677 FLAG_profile_deserialization = true; |
1666 FLAG_always_opt = false; | 1678 FLAG_always_opt = false; |
1667 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); | 1679 v8::StartupData blob = v8::V8::CreateSnapshotDataBlob(); |
1668 delete[] blob.data; | 1680 delete[] blob.data; |
1669 } | 1681 } |
OLD | NEW |