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

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

Issue 9795004: Reverted merge of r10400 and r10499 into 3.7 branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.7
Patch Set: Created 8 years, 9 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 | « src/version.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
13592 static double DoubleFromBits(uint64_t value) { 13539 static double DoubleFromBits(uint64_t value) {
13593 double target; 13540 double target;
13594 memcpy(&target, &value, sizeof(target)); 13541 memcpy(&target, &value, sizeof(target));
13595 return target; 13542 return target;
13596 } 13543 }
13597 13544
13598 13545
13599 static uint64_t DoubleToBits(double value) { 13546 static uint64_t DoubleToBits(double value) {
13600 uint64_t target; 13547 uint64_t target;
13601 memcpy(&target, &value, sizeof(target)); 13548 memcpy(&target, &value, sizeof(target));
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
13843 13790
13844 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin(); 13791 v8::ScriptOrigin script_origin_f = f->GetScriptOrigin();
13845 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_f.ResourceName())); 13792 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_f.ResourceName()));
13846 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value()); 13793 CHECK_EQ(0, script_origin_f.ResourceLineOffset()->Int32Value());
13847 13794
13848 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin(); 13795 v8::ScriptOrigin script_origin_g = g->GetScriptOrigin();
13849 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_g.ResourceName())); 13796 CHECK_EQ("test", *v8::String::AsciiValue(script_origin_g.ResourceName()));
13850 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value()); 13797 CHECK_EQ(0, script_origin_g.ResourceLineOffset()->Int32Value());
13851 } 13798 }
13852 13799
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 }
13864 13800
13865 THREADED_TEST(ScriptLineNumber) { 13801 THREADED_TEST(ScriptLineNumber) {
13866 v8::HandleScope scope; 13802 v8::HandleScope scope;
13867 LocalContext env; 13803 LocalContext env;
13868 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test")); 13804 v8::ScriptOrigin origin = v8::ScriptOrigin(v8::String::New("test"));
13869 v8::Handle<v8::String> script = v8::String::New( 13805 v8::Handle<v8::String> script = v8::String::New(
13870 "function f() {}\n\nfunction g() {}"); 13806 "function f() {}\n\nfunction g() {}");
13871 v8::Script::Compile(script, &origin)->Run(); 13807 v8::Script::Compile(script, &origin)->Run();
13872 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast( 13808 v8::Local<v8::Function> f = v8::Local<v8::Function>::Cast(
13873 env->Global()->Get(v8::String::New("f"))); 13809 env->Global()->Get(v8::String::New("f")));
(...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after
15654 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]"))); 15590 CHECK(i->Equals(CompileRun("'abcbd'.replace(/b/g,func)[3]")));
15655 15591
15656 // TODO(1547): Make the following also return "i". 15592 // TODO(1547): Make the following also return "i".
15657 // Calling with environment record as base. 15593 // Calling with environment record as base.
15658 TestReceiver(o, context->Global(), "func()"); 15594 TestReceiver(o, context->Global(), "func()");
15659 // Calling with no base. 15595 // Calling with no base.
15660 TestReceiver(o, context->Global(), "(1,func)()"); 15596 TestReceiver(o, context->Global(), "(1,func)()");
15661 15597
15662 foreign_context.Dispose(); 15598 foreign_context.Dispose();
15663 } 15599 }
OLDNEW
« no previous file with comments | « src/version.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698