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

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

Issue 6580038: [Isolates] Merge from bleeding_edge, revisions 5934-6100. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 10 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/cctest.status ('k') | test/cctest/test-heap.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 2007-2009 the V8 project authors. All rights reserved. 1 // Copyright 2007-2009 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 4325 matching lines...) Expand 10 before | Expand all | Expand 10 after
4336 CHECK_NE(obj, context->Global()->Get(v8_str("o"))); 4336 CHECK_NE(obj, context->Global()->Get(v8_str("o")));
4337 context->Global()->Set(v8_str("o2"), obj); 4337 context->Global()->Set(v8_str("o2"), obj);
4338 v8::Handle<Value> value = 4338 v8::Handle<Value> value =
4339 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run(); 4339 Script::Compile(v8_str("o.__proto__ === o2.__proto__"))->Run();
4340 CHECK_EQ(v8::True(), value); 4340 CHECK_EQ(v8::True(), value);
4341 context->Global()->Set(v8_str("o"), obj); 4341 context->Global()->Set(v8_str("o"), obj);
4342 } 4342 }
4343 } 4343 }
4344 4344
4345 4345
4346 static int StrCmp16(uint16_t* a, uint16_t* b) {
4347 while (true) {
4348 if (*a == 0 && *b == 0) return 0;
4349 if (*a != *b) return 0 + *a - *b;
4350 a++;
4351 b++;
4352 }
4353 }
4354
4355
4356 static int StrNCmp16(uint16_t* a, uint16_t* b, int n) {
4357 while (true) {
4358 if (n-- == 0) return 0;
4359 if (*a == 0 && *b == 0) return 0;
4360 if (*a != *b) return 0 + *a - *b;
4361 a++;
4362 b++;
4363 }
4364 }
4365
4366
4346 THREADED_TEST(StringWrite) { 4367 THREADED_TEST(StringWrite) {
4347 v8::HandleScope scope; 4368 v8::HandleScope scope;
4348 v8::Handle<String> str = v8_str("abcde"); 4369 v8::Handle<String> str = v8_str("abcde");
4370 // abc<Icelandic eth><Unicode snowman>.
4371 v8::Handle<String> str2 = v8_str("abc\303\260\342\230\203");
4372
4373 CHECK_EQ(5, str2->Length());
4349 4374
4350 char buf[100]; 4375 char buf[100];
4376 char utf8buf[100];
4377 uint16_t wbuf[100];
4351 int len; 4378 int len;
4379 int charlen;
4380
4381 memset(utf8buf, 0x1, sizeof(utf8buf));
4382 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen);
4383 CHECK_EQ(len, 9);
4384 CHECK_EQ(charlen, 5);
4385 CHECK_EQ(strcmp(utf8buf, "abc\303\260\342\230\203"), 0);
4386
4387 memset(utf8buf, 0x1, sizeof(utf8buf));
4388 len = str2->WriteUtf8(utf8buf, 8, &charlen);
4389 CHECK_EQ(len, 8);
4390 CHECK_EQ(charlen, 5);
4391 CHECK_EQ(strncmp(utf8buf, "abc\303\260\342\230\203\1", 9), 0);
4392
4393 memset(utf8buf, 0x1, sizeof(utf8buf));
4394 len = str2->WriteUtf8(utf8buf, 7, &charlen);
4395 CHECK_EQ(len, 5);
4396 CHECK_EQ(charlen, 4);
4397 CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0);
4398
4399 memset(utf8buf, 0x1, sizeof(utf8buf));
4400 len = str2->WriteUtf8(utf8buf, 6, &charlen);
4401 CHECK_EQ(len, 5);
4402 CHECK_EQ(charlen, 4);
4403 CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0);
4404
4405 memset(utf8buf, 0x1, sizeof(utf8buf));
4406 len = str2->WriteUtf8(utf8buf, 5, &charlen);
4407 CHECK_EQ(len, 5);
4408 CHECK_EQ(charlen, 4);
4409 CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0);
4410
4411 memset(utf8buf, 0x1, sizeof(utf8buf));
4412 len = str2->WriteUtf8(utf8buf, 4, &charlen);
4413 CHECK_EQ(len, 3);
4414 CHECK_EQ(charlen, 3);
4415 CHECK_EQ(strncmp(utf8buf, "abc\1", 4), 0);
4416
4417 memset(utf8buf, 0x1, sizeof(utf8buf));
4418 len = str2->WriteUtf8(utf8buf, 3, &charlen);
4419 CHECK_EQ(len, 3);
4420 CHECK_EQ(charlen, 3);
4421 CHECK_EQ(strncmp(utf8buf, "abc\1", 4), 0);
4422
4423 memset(utf8buf, 0x1, sizeof(utf8buf));
4424 len = str2->WriteUtf8(utf8buf, 2, &charlen);
4425 CHECK_EQ(len, 2);
4426 CHECK_EQ(charlen, 2);
4427 CHECK_EQ(strncmp(utf8buf, "ab\1", 3), 0);
4352 4428
4353 memset(buf, 0x1, sizeof(buf)); 4429 memset(buf, 0x1, sizeof(buf));
4430 memset(wbuf, 0x1, sizeof(wbuf));
4354 len = str->WriteAscii(buf); 4431 len = str->WriteAscii(buf);
4355 CHECK_EQ(len, 5); 4432 CHECK_EQ(len, 5);
4356 CHECK_EQ(strncmp("abcde\0", buf, 6), 0); 4433 len = str->Write(wbuf);
4434 CHECK_EQ(len, 5);
4435 CHECK_EQ(strcmp("abcde", buf), 0);
4436 uint16_t answer1[] = {'a', 'b', 'c', 'd', 'e', '\0'};
4437 CHECK_EQ(StrCmp16(answer1, wbuf), 0);
4357 4438
4358 memset(buf, 0x1, sizeof(buf)); 4439 memset(buf, 0x1, sizeof(buf));
4440 memset(wbuf, 0x1, sizeof(wbuf));
4359 len = str->WriteAscii(buf, 0, 4); 4441 len = str->WriteAscii(buf, 0, 4);
4360 CHECK_EQ(len, 4); 4442 CHECK_EQ(len, 4);
4443 len = str->Write(wbuf, 0, 4);
4444 CHECK_EQ(len, 4);
4361 CHECK_EQ(strncmp("abcd\1", buf, 5), 0); 4445 CHECK_EQ(strncmp("abcd\1", buf, 5), 0);
4446 uint16_t answer2[] = {'a', 'b', 'c', 'd', 0x101};
4447 CHECK_EQ(StrNCmp16(answer2, wbuf, 5), 0);
4362 4448
4363 memset(buf, 0x1, sizeof(buf)); 4449 memset(buf, 0x1, sizeof(buf));
4450 memset(wbuf, 0x1, sizeof(wbuf));
4364 len = str->WriteAscii(buf, 0, 5); 4451 len = str->WriteAscii(buf, 0, 5);
4365 CHECK_EQ(len, 5); 4452 CHECK_EQ(len, 5);
4453 len = str->Write(wbuf, 0, 5);
4454 CHECK_EQ(len, 5);
4366 CHECK_EQ(strncmp("abcde\1", buf, 6), 0); 4455 CHECK_EQ(strncmp("abcde\1", buf, 6), 0);
4456 uint16_t answer3[] = {'a', 'b', 'c', 'd', 'e', 0x101};
4457 CHECK_EQ(StrNCmp16(answer3, wbuf, 6), 0);
4367 4458
4368 memset(buf, 0x1, sizeof(buf)); 4459 memset(buf, 0x1, sizeof(buf));
4460 memset(wbuf, 0x1, sizeof(wbuf));
4369 len = str->WriteAscii(buf, 0, 6); 4461 len = str->WriteAscii(buf, 0, 6);
4370 CHECK_EQ(len, 5); 4462 CHECK_EQ(len, 5);
4371 CHECK_EQ(strncmp("abcde\0", buf, 6), 0); 4463 len = str->Write(wbuf, 0, 6);
4464 CHECK_EQ(len, 5);
4465 CHECK_EQ(strcmp("abcde", buf), 0);
4466 uint16_t answer4[] = {'a', 'b', 'c', 'd', 'e', '\0'};
4467 CHECK_EQ(StrCmp16(answer4, wbuf), 0);
4372 4468
4373 memset(buf, 0x1, sizeof(buf)); 4469 memset(buf, 0x1, sizeof(buf));
4470 memset(wbuf, 0x1, sizeof(wbuf));
4374 len = str->WriteAscii(buf, 4, -1); 4471 len = str->WriteAscii(buf, 4, -1);
4375 CHECK_EQ(len, 1); 4472 CHECK_EQ(len, 1);
4376 CHECK_EQ(strncmp("e\0", buf, 2), 0); 4473 len = str->Write(wbuf, 4, -1);
4474 CHECK_EQ(len, 1);
4475 CHECK_EQ(strcmp("e", buf), 0);
4476 uint16_t answer5[] = {'e', '\0'};
4477 CHECK_EQ(StrCmp16(answer5, wbuf), 0);
4377 4478
4378 memset(buf, 0x1, sizeof(buf)); 4479 memset(buf, 0x1, sizeof(buf));
4480 memset(wbuf, 0x1, sizeof(wbuf));
4379 len = str->WriteAscii(buf, 4, 6); 4481 len = str->WriteAscii(buf, 4, 6);
4380 CHECK_EQ(len, 1); 4482 CHECK_EQ(len, 1);
4381 CHECK_EQ(strncmp("e\0", buf, 2), 0); 4483 len = str->Write(wbuf, 4, 6);
4484 CHECK_EQ(len, 1);
4485 CHECK_EQ(strcmp("e", buf), 0);
4486 CHECK_EQ(StrCmp16(answer5, wbuf), 0);
4382 4487
4383 memset(buf, 0x1, sizeof(buf)); 4488 memset(buf, 0x1, sizeof(buf));
4489 memset(wbuf, 0x1, sizeof(wbuf));
4384 len = str->WriteAscii(buf, 4, 1); 4490 len = str->WriteAscii(buf, 4, 1);
4385 CHECK_EQ(len, 1); 4491 CHECK_EQ(len, 1);
4492 len = str->Write(wbuf, 4, 1);
4493 CHECK_EQ(len, 1);
4386 CHECK_EQ(strncmp("e\1", buf, 2), 0); 4494 CHECK_EQ(strncmp("e\1", buf, 2), 0);
4495 uint16_t answer6[] = {'e', 0x101};
4496 CHECK_EQ(StrNCmp16(answer6, wbuf, 2), 0);
4497
4498 memset(buf, 0x1, sizeof(buf));
4499 memset(wbuf, 0x1, sizeof(wbuf));
4500 len = str->WriteAscii(buf, 3, 1);
4501 CHECK_EQ(len, 1);
4502 len = str->Write(wbuf, 3, 1);
4503 CHECK_EQ(len, 1);
4504 CHECK_EQ(strncmp("d\1", buf, 2), 0);
4505 uint16_t answer7[] = {'d', 0x101};
4506 CHECK_EQ(StrNCmp16(answer7, wbuf, 2), 0);
4387 } 4507 }
4388 4508
4389 4509
4390 THREADED_TEST(ToArrayIndex) { 4510 THREADED_TEST(ToArrayIndex) {
4391 v8::HandleScope scope; 4511 v8::HandleScope scope;
4392 LocalContext context; 4512 LocalContext context;
4393 4513
4394 v8::Handle<String> str = v8_str("42"); 4514 v8::Handle<String> str = v8_str("42");
4395 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); 4515 v8::Handle<v8::Uint32> index = str->ToArrayIndex();
4396 CHECK(!index.IsEmpty()); 4516 CHECK(!index.IsEmpty());
(...skipping 7860 matching lines...) Expand 10 before | Expand all | Expand 10 after
12257 v8::Context::Scope context_scope(context.local()); 12377 v8::Context::Scope context_scope(context.local());
12258 12378
12259 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New(); 12379 v8::Handle<v8::ObjectTemplate> tmpl = v8::ObjectTemplate::New();
12260 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator); 12380 tmpl->SetNamedPropertyHandler(Getter, NULL, NULL, NULL, Enumerator);
12261 context->Global()->Set(v8_str("o"), tmpl->NewInstance()); 12381 context->Global()->Set(v8_str("o"), tmpl->NewInstance());
12262 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun( 12382 v8::Handle<v8::Array> result = v8::Handle<v8::Array>::Cast(CompileRun(
12263 "var result = []; for (var k in o) result.push(k); result")); 12383 "var result = []; for (var k in o) result.push(k); result"));
12264 CHECK_EQ(1, result->Length()); 12384 CHECK_EQ(1, result->Length());
12265 CHECK_EQ(v8_str("universalAnswer"), result->Get(0)); 12385 CHECK_EQ(v8_str("universalAnswer"), result->Get(0));
12266 } 12386 }
OLDNEW
« no previous file with comments | « test/cctest/cctest.status ('k') | test/cctest/test-heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698