OLD | NEW |
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 4726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4737 CHECK_EQ(5, str2->Length()); | 4737 CHECK_EQ(5, str2->Length()); |
4738 | 4738 |
4739 char buf[100]; | 4739 char buf[100]; |
4740 char utf8buf[100]; | 4740 char utf8buf[100]; |
4741 uint16_t wbuf[100]; | 4741 uint16_t wbuf[100]; |
4742 int len; | 4742 int len; |
4743 int charlen; | 4743 int charlen; |
4744 | 4744 |
4745 memset(utf8buf, 0x1, sizeof(utf8buf)); | 4745 memset(utf8buf, 0x1, sizeof(utf8buf)); |
4746 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen); | 4746 len = str2->WriteUtf8(utf8buf, sizeof(utf8buf), &charlen); |
4747 CHECK_EQ(len, 9); | 4747 CHECK_EQ(9, len); |
4748 CHECK_EQ(charlen, 5); | 4748 CHECK_EQ(5, charlen); |
4749 CHECK_EQ(strcmp(utf8buf, "abc\303\260\342\230\203"), 0); | 4749 CHECK_EQ(0, strcmp(utf8buf, "abc\303\260\342\230\203")); |
4750 | 4750 |
4751 memset(utf8buf, 0x1, sizeof(utf8buf)); | 4751 memset(utf8buf, 0x1, sizeof(utf8buf)); |
4752 len = str2->WriteUtf8(utf8buf, 8, &charlen); | 4752 len = str2->WriteUtf8(utf8buf, 8, &charlen); |
4753 CHECK_EQ(len, 8); | 4753 CHECK_EQ(8, len); |
4754 CHECK_EQ(charlen, 5); | 4754 CHECK_EQ(5, charlen); |
4755 CHECK_EQ(strncmp(utf8buf, "abc\303\260\342\230\203\1", 9), 0); | 4755 CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\342\230\203\1", 9)); |
4756 | 4756 |
4757 memset(utf8buf, 0x1, sizeof(utf8buf)); | 4757 memset(utf8buf, 0x1, sizeof(utf8buf)); |
4758 len = str2->WriteUtf8(utf8buf, 7, &charlen); | 4758 len = str2->WriteUtf8(utf8buf, 7, &charlen); |
4759 CHECK_EQ(len, 5); | 4759 CHECK_EQ(5, len); |
4760 CHECK_EQ(charlen, 4); | 4760 CHECK_EQ(4, charlen); |
4761 CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0); | 4761 CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\1", 5)); |
4762 | 4762 |
4763 memset(utf8buf, 0x1, sizeof(utf8buf)); | 4763 memset(utf8buf, 0x1, sizeof(utf8buf)); |
4764 len = str2->WriteUtf8(utf8buf, 6, &charlen); | 4764 len = str2->WriteUtf8(utf8buf, 6, &charlen); |
4765 CHECK_EQ(len, 5); | 4765 CHECK_EQ(5, len); |
4766 CHECK_EQ(charlen, 4); | 4766 CHECK_EQ(4, charlen); |
4767 CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0); | 4767 CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\1", 5)); |
4768 | 4768 |
4769 memset(utf8buf, 0x1, sizeof(utf8buf)); | 4769 memset(utf8buf, 0x1, sizeof(utf8buf)); |
4770 len = str2->WriteUtf8(utf8buf, 5, &charlen); | 4770 len = str2->WriteUtf8(utf8buf, 5, &charlen); |
4771 CHECK_EQ(len, 5); | 4771 CHECK_EQ(5, len); |
4772 CHECK_EQ(charlen, 4); | 4772 CHECK_EQ(4, charlen); |
4773 CHECK_EQ(strncmp(utf8buf, "abc\303\260\1", 5), 0); | 4773 CHECK_EQ(0, strncmp(utf8buf, "abc\303\260\1", 5)); |
4774 | 4774 |
4775 memset(utf8buf, 0x1, sizeof(utf8buf)); | 4775 memset(utf8buf, 0x1, sizeof(utf8buf)); |
4776 len = str2->WriteUtf8(utf8buf, 4, &charlen); | 4776 len = str2->WriteUtf8(utf8buf, 4, &charlen); |
4777 CHECK_EQ(len, 3); | 4777 CHECK_EQ(3, len); |
4778 CHECK_EQ(charlen, 3); | 4778 CHECK_EQ(3, charlen); |
4779 CHECK_EQ(strncmp(utf8buf, "abc\1", 4), 0); | 4779 CHECK_EQ(0, strncmp(utf8buf, "abc\1", 4)); |
4780 | 4780 |
4781 memset(utf8buf, 0x1, sizeof(utf8buf)); | 4781 memset(utf8buf, 0x1, sizeof(utf8buf)); |
4782 len = str2->WriteUtf8(utf8buf, 3, &charlen); | 4782 len = str2->WriteUtf8(utf8buf, 3, &charlen); |
4783 CHECK_EQ(len, 3); | 4783 CHECK_EQ(3, len); |
4784 CHECK_EQ(charlen, 3); | 4784 CHECK_EQ(3, charlen); |
4785 CHECK_EQ(strncmp(utf8buf, "abc\1", 4), 0); | 4785 CHECK_EQ(0, strncmp(utf8buf, "abc\1", 4)); |
4786 | 4786 |
4787 memset(utf8buf, 0x1, sizeof(utf8buf)); | 4787 memset(utf8buf, 0x1, sizeof(utf8buf)); |
4788 len = str2->WriteUtf8(utf8buf, 2, &charlen); | 4788 len = str2->WriteUtf8(utf8buf, 2, &charlen); |
4789 CHECK_EQ(len, 2); | 4789 CHECK_EQ(2, len); |
4790 CHECK_EQ(charlen, 2); | 4790 CHECK_EQ(2, charlen); |
4791 CHECK_EQ(strncmp(utf8buf, "ab\1", 3), 0); | 4791 CHECK_EQ(0, strncmp(utf8buf, "ab\1", 3)); |
4792 | 4792 |
4793 memset(buf, 0x1, sizeof(buf)); | 4793 memset(buf, 0x1, sizeof(buf)); |
4794 memset(wbuf, 0x1, sizeof(wbuf)); | 4794 memset(wbuf, 0x1, sizeof(wbuf)); |
4795 len = str->WriteAscii(buf); | 4795 len = str->WriteAscii(buf); |
4796 CHECK_EQ(len, 5); | 4796 CHECK_EQ(5, len); |
4797 len = str->Write(wbuf); | 4797 len = str->Write(wbuf); |
4798 CHECK_EQ(len, 5); | 4798 CHECK_EQ(5, len); |
4799 CHECK_EQ(strcmp("abcde", buf), 0); | 4799 CHECK_EQ(0, strcmp("abcde", buf)); |
4800 uint16_t answer1[] = {'a', 'b', 'c', 'd', 'e', '\0'}; | 4800 uint16_t answer1[] = {'a', 'b', 'c', 'd', 'e', '\0'}; |
4801 CHECK_EQ(StrCmp16(answer1, wbuf), 0); | 4801 CHECK_EQ(0, StrCmp16(answer1, wbuf)); |
4802 | 4802 |
4803 memset(buf, 0x1, sizeof(buf)); | 4803 memset(buf, 0x1, sizeof(buf)); |
4804 memset(wbuf, 0x1, sizeof(wbuf)); | 4804 memset(wbuf, 0x1, sizeof(wbuf)); |
4805 len = str->WriteAscii(buf, 0, 4); | 4805 len = str->WriteAscii(buf, 0, 4); |
4806 CHECK_EQ(len, 4); | 4806 CHECK_EQ(4, len); |
4807 len = str->Write(wbuf, 0, 4); | 4807 len = str->Write(wbuf, 0, 4); |
4808 CHECK_EQ(len, 4); | 4808 CHECK_EQ(4, len); |
4809 CHECK_EQ(strncmp("abcd\1", buf, 5), 0); | 4809 CHECK_EQ(0, strncmp("abcd\1", buf, 5)); |
4810 uint16_t answer2[] = {'a', 'b', 'c', 'd', 0x101}; | 4810 uint16_t answer2[] = {'a', 'b', 'c', 'd', 0x101}; |
4811 CHECK_EQ(StrNCmp16(answer2, wbuf, 5), 0); | 4811 CHECK_EQ(0, StrNCmp16(answer2, wbuf, 5)); |
4812 | 4812 |
4813 memset(buf, 0x1, sizeof(buf)); | 4813 memset(buf, 0x1, sizeof(buf)); |
4814 memset(wbuf, 0x1, sizeof(wbuf)); | 4814 memset(wbuf, 0x1, sizeof(wbuf)); |
4815 len = str->WriteAscii(buf, 0, 5); | 4815 len = str->WriteAscii(buf, 0, 5); |
4816 CHECK_EQ(len, 5); | 4816 CHECK_EQ(5, len); |
4817 len = str->Write(wbuf, 0, 5); | 4817 len = str->Write(wbuf, 0, 5); |
4818 CHECK_EQ(len, 5); | 4818 CHECK_EQ(5, len); |
4819 CHECK_EQ(strncmp("abcde\1", buf, 6), 0); | 4819 CHECK_EQ(0, strncmp("abcde\1", buf, 6)); |
4820 uint16_t answer3[] = {'a', 'b', 'c', 'd', 'e', 0x101}; | 4820 uint16_t answer3[] = {'a', 'b', 'c', 'd', 'e', 0x101}; |
4821 CHECK_EQ(StrNCmp16(answer3, wbuf, 6), 0); | 4821 CHECK_EQ(0, StrNCmp16(answer3, wbuf, 6)); |
4822 | 4822 |
4823 memset(buf, 0x1, sizeof(buf)); | 4823 memset(buf, 0x1, sizeof(buf)); |
4824 memset(wbuf, 0x1, sizeof(wbuf)); | 4824 memset(wbuf, 0x1, sizeof(wbuf)); |
4825 len = str->WriteAscii(buf, 0, 6); | 4825 len = str->WriteAscii(buf, 0, 6); |
4826 CHECK_EQ(len, 5); | 4826 CHECK_EQ(5, len); |
4827 len = str->Write(wbuf, 0, 6); | 4827 len = str->Write(wbuf, 0, 6); |
4828 CHECK_EQ(len, 5); | 4828 CHECK_EQ(5, len); |
4829 CHECK_EQ(strcmp("abcde", buf), 0); | 4829 CHECK_EQ(0, strcmp("abcde", buf)); |
4830 uint16_t answer4[] = {'a', 'b', 'c', 'd', 'e', '\0'}; | 4830 uint16_t answer4[] = {'a', 'b', 'c', 'd', 'e', '\0'}; |
4831 CHECK_EQ(StrCmp16(answer4, wbuf), 0); | 4831 CHECK_EQ(0, StrCmp16(answer4, wbuf)); |
4832 | 4832 |
4833 memset(buf, 0x1, sizeof(buf)); | 4833 memset(buf, 0x1, sizeof(buf)); |
4834 memset(wbuf, 0x1, sizeof(wbuf)); | 4834 memset(wbuf, 0x1, sizeof(wbuf)); |
4835 len = str->WriteAscii(buf, 4, -1); | 4835 len = str->WriteAscii(buf, 4, -1); |
4836 CHECK_EQ(len, 1); | 4836 CHECK_EQ(1, len); |
4837 len = str->Write(wbuf, 4, -1); | 4837 len = str->Write(wbuf, 4, -1); |
4838 CHECK_EQ(len, 1); | 4838 CHECK_EQ(1, len); |
4839 CHECK_EQ(strcmp("e", buf), 0); | 4839 CHECK_EQ(0, strcmp("e", buf)); |
4840 uint16_t answer5[] = {'e', '\0'}; | 4840 uint16_t answer5[] = {'e', '\0'}; |
4841 CHECK_EQ(StrCmp16(answer5, wbuf), 0); | 4841 CHECK_EQ(0, StrCmp16(answer5, wbuf)); |
4842 | 4842 |
4843 memset(buf, 0x1, sizeof(buf)); | 4843 memset(buf, 0x1, sizeof(buf)); |
4844 memset(wbuf, 0x1, sizeof(wbuf)); | 4844 memset(wbuf, 0x1, sizeof(wbuf)); |
4845 len = str->WriteAscii(buf, 4, 6); | 4845 len = str->WriteAscii(buf, 4, 6); |
4846 CHECK_EQ(len, 1); | 4846 CHECK_EQ(1, len); |
4847 len = str->Write(wbuf, 4, 6); | 4847 len = str->Write(wbuf, 4, 6); |
4848 CHECK_EQ(len, 1); | 4848 CHECK_EQ(1, len); |
4849 CHECK_EQ(strcmp("e", buf), 0); | 4849 CHECK_EQ(0, strcmp("e", buf)); |
4850 CHECK_EQ(StrCmp16(answer5, wbuf), 0); | 4850 CHECK_EQ(0, StrCmp16(answer5, wbuf)); |
4851 | 4851 |
4852 memset(buf, 0x1, sizeof(buf)); | 4852 memset(buf, 0x1, sizeof(buf)); |
4853 memset(wbuf, 0x1, sizeof(wbuf)); | 4853 memset(wbuf, 0x1, sizeof(wbuf)); |
4854 len = str->WriteAscii(buf, 4, 1); | 4854 len = str->WriteAscii(buf, 4, 1); |
4855 CHECK_EQ(len, 1); | 4855 CHECK_EQ(1, len); |
4856 len = str->Write(wbuf, 4, 1); | 4856 len = str->Write(wbuf, 4, 1); |
4857 CHECK_EQ(len, 1); | 4857 CHECK_EQ(1, len); |
4858 CHECK_EQ(strncmp("e\1", buf, 2), 0); | 4858 CHECK_EQ(0, strncmp("e\1", buf, 2)); |
4859 uint16_t answer6[] = {'e', 0x101}; | 4859 uint16_t answer6[] = {'e', 0x101}; |
4860 CHECK_EQ(StrNCmp16(answer6, wbuf, 2), 0); | 4860 CHECK_EQ(0, StrNCmp16(answer6, wbuf, 2)); |
4861 | 4861 |
4862 memset(buf, 0x1, sizeof(buf)); | 4862 memset(buf, 0x1, sizeof(buf)); |
4863 memset(wbuf, 0x1, sizeof(wbuf)); | 4863 memset(wbuf, 0x1, sizeof(wbuf)); |
4864 len = str->WriteAscii(buf, 3, 1); | 4864 len = str->WriteAscii(buf, 3, 1); |
4865 CHECK_EQ(len, 1); | 4865 CHECK_EQ(1, len); |
4866 len = str->Write(wbuf, 3, 1); | 4866 len = str->Write(wbuf, 3, 1); |
4867 CHECK_EQ(len, 1); | 4867 CHECK_EQ(1, len); |
4868 CHECK_EQ(strncmp("d\1", buf, 2), 0); | 4868 CHECK_EQ(0, strncmp("d\1", buf, 2)); |
4869 uint16_t answer7[] = {'d', 0x101}; | 4869 uint16_t answer7[] = {'d', 0x101}; |
4870 CHECK_EQ(StrNCmp16(answer7, wbuf, 2), 0); | 4870 CHECK_EQ(0, StrNCmp16(answer7, wbuf, 2)); |
4871 } | 4871 } |
4872 | 4872 |
4873 | 4873 |
4874 THREADED_TEST(ToArrayIndex) { | 4874 THREADED_TEST(ToArrayIndex) { |
4875 v8::HandleScope scope; | 4875 v8::HandleScope scope; |
4876 LocalContext context; | 4876 LocalContext context; |
4877 | 4877 |
4878 v8::Handle<String> str = v8_str("42"); | 4878 v8::Handle<String> str = v8_str("42"); |
4879 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); | 4879 v8::Handle<v8::Uint32> index = str->ToArrayIndex(); |
4880 CHECK(!index.IsEmpty()); | 4880 CHECK(!index.IsEmpty()); |
(...skipping 8683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13564 v8::Handle<v8::Function> define_property = | 13564 v8::Handle<v8::Function> define_property = |
13565 CompileRun("(function() {" | 13565 CompileRun("(function() {" |
13566 " Object.defineProperty(" | 13566 " Object.defineProperty(" |
13567 " this," | 13567 " this," |
13568 " 1," | 13568 " 1," |
13569 " { configurable: true, enumerable: true, value: 3 });" | 13569 " { configurable: true, enumerable: true, value: 3 });" |
13570 "})").As<Function>(); | 13570 "})").As<Function>(); |
13571 context->DetachGlobal(); | 13571 context->DetachGlobal(); |
13572 define_property->Call(proxy, 0, NULL); | 13572 define_property->Call(proxy, 0, NULL); |
13573 } | 13573 } |
OLD | NEW |