| OLD | NEW |
| 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 7510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7521 Local<Value> s4 = global->Get(v8_str("sym4")); | 7521 Local<Value> s4 = global->Get(v8_str("sym4")); |
| 7522 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0))); | 7522 CHECK(SameSymbol(sym0, Handle<String>::Cast(s0))); |
| 7523 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); | 7523 CHECK(SameSymbol(sym0b, Handle<String>::Cast(s0b))); |
| 7524 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); | 7524 CHECK(SameSymbol(sym1, Handle<String>::Cast(s1))); |
| 7525 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); | 7525 CHECK(SameSymbol(sym2, Handle<String>::Cast(s2))); |
| 7526 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); | 7526 CHECK(SameSymbol(sym3, Handle<String>::Cast(s3))); |
| 7527 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); | 7527 CHECK(SameSymbol(sym4, Handle<String>::Cast(s4))); |
| 7528 } | 7528 } |
| 7529 | 7529 |
| 7530 | 7530 |
| 7531 THREADED_TEST(Utf16MissingTrailing) { |
| 7532 LocalContext context; |
| 7533 v8::HandleScope scope(context->GetIsolate()); |
| 7534 |
| 7535 // Make sure it will go past the buffer, so it will call `WriteUtf16Slow` |
| 7536 int size = 1024 * 64; |
| 7537 uint8_t* buffer = new uint8_t[size]; |
| 7538 for (int i = 0; i < size; i += 4) { |
| 7539 buffer[i] = 0xf0; |
| 7540 buffer[i + 1] = 0x9d; |
| 7541 buffer[i + 2] = 0x80; |
| 7542 buffer[i + 3] = 0x9e; |
| 7543 } |
| 7544 |
| 7545 // Now invoke the decoder without last 3 bytes |
| 7546 v8::Local<v8::String> str = |
| 7547 v8::String::NewFromUtf8( |
| 7548 context->GetIsolate(), reinterpret_cast<char*>(buffer), |
| 7549 v8::NewStringType::kNormal, size - 3).ToLocalChecked(); |
| 7550 USE(str); |
| 7551 delete[] buffer; |
| 7552 } |
| 7553 |
| 7554 |
| 7555 THREADED_TEST(Utf16Trailing3Byte) { |
| 7556 LocalContext context; |
| 7557 v8::HandleScope scope(context->GetIsolate()); |
| 7558 |
| 7559 // Make sure it will go past the buffer, so it will call `WriteUtf16Slow` |
| 7560 int size = 1024 * 63; |
| 7561 uint8_t* buffer = new uint8_t[size]; |
| 7562 for (int i = 0; i < size; i += 3) { |
| 7563 buffer[i] = 0xe2; |
| 7564 buffer[i + 1] = 0x80; |
| 7565 buffer[i + 2] = 0xa6; |
| 7566 } |
| 7567 |
| 7568 // Now invoke the decoder without last 3 bytes |
| 7569 v8::Local<v8::String> str = |
| 7570 v8::String::NewFromUtf8( |
| 7571 context->GetIsolate(), reinterpret_cast<char*>(buffer), |
| 7572 v8::NewStringType::kNormal, size).ToLocalChecked(); |
| 7573 |
| 7574 v8::String::Value value(str); |
| 7575 CHECK_EQ(value.length(), size / 3); |
| 7576 CHECK_EQ((*value)[value.length() - 1], 0x2026); |
| 7577 |
| 7578 delete[] buffer; |
| 7579 } |
| 7580 |
| 7581 |
| 7531 THREADED_TEST(ToArrayIndex) { | 7582 THREADED_TEST(ToArrayIndex) { |
| 7532 LocalContext context; | 7583 LocalContext context; |
| 7533 v8::Isolate* isolate = context->GetIsolate(); | 7584 v8::Isolate* isolate = context->GetIsolate(); |
| 7534 v8::HandleScope scope(isolate); | 7585 v8::HandleScope scope(isolate); |
| 7535 | 7586 |
| 7536 v8::Handle<String> str = v8_str("42"); | 7587 v8::Handle<String> str = v8_str("42"); |
| 7537 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); | 7588 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); |
| 7538 CHECK(!index.IsEmpty()); | 7589 CHECK(!index.IsEmpty()); |
| 7539 CHECK_EQ(42.0, index->Uint32Value()); | 7590 CHECK_EQ(42.0, index->Uint32Value()); |
| 7540 str = v8_str("42asdf"); | 7591 str = v8_str("42asdf"); |
| (...skipping 14328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21869 } | 21920 } |
| 21870 { | 21921 { |
| 21871 v8::TryCatch try_catch; | 21922 v8::TryCatch try_catch; |
| 21872 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); | 21923 uint16_t* data = reinterpret_cast<uint16_t*>(buffer); |
| 21873 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, | 21924 CHECK(v8::String::NewFromTwoByte(isolate, data, v8::String::kNormalString, |
| 21874 length).IsEmpty()); | 21925 length).IsEmpty()); |
| 21875 CHECK(!try_catch.HasCaught()); | 21926 CHECK(!try_catch.HasCaught()); |
| 21876 } | 21927 } |
| 21877 free(buffer); | 21928 free(buffer); |
| 21878 } | 21929 } |
| OLD | NEW |