OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 13518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13529 LocalContext c1; | 13529 LocalContext c1; |
13530 v8::HeapStatistics heap_statistics; | 13530 v8::HeapStatistics heap_statistics; |
13531 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); | 13531 CHECK_EQ(static_cast<int>(heap_statistics.total_heap_size()), 0); |
13532 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); | 13532 CHECK_EQ(static_cast<int>(heap_statistics.used_heap_size()), 0); |
13533 v8::V8::GetHeapStatistics(&heap_statistics); | 13533 v8::V8::GetHeapStatistics(&heap_statistics); |
13534 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); | 13534 CHECK_NE(static_cast<int>(heap_statistics.total_heap_size()), 0); |
13535 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); | 13535 CHECK_NE(static_cast<int>(heap_statistics.used_heap_size()), 0); |
13536 } | 13536 } |
13537 | 13537 |
13538 | 13538 |
| 13539 class VisitorImpl : public v8::ExternalResourceVisitor { |
| 13540 public: |
| 13541 VisitorImpl(TestResource* r1, TestResource* r2) |
| 13542 : resource1_(r1), |
| 13543 resource2_(r2), |
| 13544 found_resource1_(false), |
| 13545 found_resource2_(false) {} |
| 13546 virtual ~VisitorImpl() {} |
| 13547 virtual void VisitExternalString(v8::Handle<v8::String> string) { |
| 13548 if (!string->IsExternal()) { |
| 13549 CHECK(string->IsExternalAscii()); |
| 13550 return; |
| 13551 } |
| 13552 v8::String::ExternalStringResource* resource = |
| 13553 string->GetExternalStringResource(); |
| 13554 CHECK(resource); |
| 13555 if (resource1_ == resource) { |
| 13556 CHECK(!found_resource1_); |
| 13557 found_resource1_ = true; |
| 13558 } |
| 13559 if (resource2_ == resource) { |
| 13560 CHECK(!found_resource2_); |
| 13561 found_resource2_ = true; |
| 13562 } |
| 13563 } |
| 13564 void CheckVisitedResources() { |
| 13565 CHECK(found_resource1_); |
| 13566 CHECK(found_resource2_); |
| 13567 } |
| 13568 |
| 13569 private: |
| 13570 v8::String::ExternalStringResource* resource1_; |
| 13571 v8::String::ExternalStringResource* resource2_; |
| 13572 bool found_resource1_; |
| 13573 bool found_resource2_; |
| 13574 }; |
| 13575 |
| 13576 TEST(VisitExternalStrings) { |
| 13577 v8::HandleScope scope; |
| 13578 LocalContext env; |
| 13579 const char* string = "Some string"; |
| 13580 uint16_t* two_byte_string = AsciiToTwoByteString(string); |
| 13581 TestResource* resource1 = new TestResource(two_byte_string); |
| 13582 v8::Local<v8::String> string1 = v8::String::NewExternal(resource1); |
| 13583 TestResource* resource2 = new TestResource(two_byte_string); |
| 13584 v8::Local<v8::String> string2 = v8::String::NewExternal(resource2); |
| 13585 |
| 13586 VisitorImpl visitor(resource1, resource2); |
| 13587 v8::V8::VisitExternalResources(&visitor); |
| 13588 visitor.CheckVisitedResources(); |
| 13589 } |
| 13590 |
| 13591 |
13539 static double DoubleFromBits(uint64_t value) { | 13592 static double DoubleFromBits(uint64_t value) { |
13540 double target; | 13593 double target; |
13541 memcpy(&target, &value, sizeof(target)); | 13594 memcpy(&target, &value, sizeof(target)); |
13542 return target; | 13595 return target; |
13543 } | 13596 } |
13544 | 13597 |
13545 | 13598 |
13546 static uint64_t DoubleToBits(double value) { | 13599 static uint64_t DoubleToBits(double value) { |
13547 uint64_t target; | 13600 uint64_t target; |
13548 memcpy(&target, &value, sizeof(target)); | 13601 memcpy(&target, &value, sizeof(target)); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13790 | 13843 |
13791 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); | 13844 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); |
13792 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_f.ResourceName())); | 13845 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_f.ResourceName())); |
13793 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value()); | 13846 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value()); |
13794 | 13847 |
13795 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); | 13848 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); |
13796 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_g.ResourceName())); | 13849 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_g.ResourceName())); |
13797 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value()); | 13850 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value()); |
13798 } | 13851 } |
13799 | 13852 |
| 13853 THREADED_TEST(FunctionGetInferredName) { |
| 13854 v8::HandleScope scope; |
| 13855 LocalContext env; |
| 13856 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); |
| 13857 v8::Handle<v8::String> script = v8::String::New( |
| 13858 "var foo = { bar : { baz : function() {}}}; var f = foo.bar.baz;"); |
| 13859 v8::Script::Compile(script, &origin)->Run(); |
| 13860 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
| 13861 env->Global()->Get(v8::String::New("f"))); |
| 13862 CHECK_EQ("foo.bar.baz", *v8::String::AsciiValue(f->GetInferredName())); |
| 13863 } |
13800 | 13864 |
13801 THREADED_TEST(ScriptLineNumber) { | 13865 THREADED_TEST(ScriptLineNumber) { |
13802 v8::HandleScope scope; | 13866 v8::HandleScope scope; |
13803 LocalContext env; | 13867 LocalContext env; |
13804 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); | 13868 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); |
13805 v8::Handle<v8::String> script = v8::String::New( | 13869 v8::Handle<v8::String> script = v8::String::New( |
13806 "function f() {}\n\nfunction g() {}"); | 13870 "function f() {}\n\nfunction g() {}"); |
13807 v8::Script::Compile(script, &origin)->Run(); | 13871 v8::Script::Compile(script, &origin)->Run(); |
13808 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( | 13872 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( |
13809 env->Global()->Get(v8::String::New("f"))); | 13873 env->Global()->Get(v8::String::New("f"))); |
(...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15590 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); | 15654 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); |
15591 | 15655 |
15592 // TODO(1547): Make the following also return "i". | 15656 // TODO(1547): Make the following also return "i". |
15593 // Calling with environment record as base. | 15657 // Calling with environment record as base. |
15594 TestReceiver(o, context->Global(), "func()"); | 15658 TestReceiver(o, context->Global(), "func()"); |
15595 // Calling with no base. | 15659 // Calling with no base. |
15596 TestReceiver(o, context->Global(), "(1,func)()"); | 15660 TestReceiver(o, context->Global(), "(1,func)()"); |
15597 | 15661 |
15598 foreign_context.Dispose(); | 15662 foreign_context.Dispose(); |
15599 } | 15663 } |
OLD | NEW |