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 13984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13995 #define TEST_TOSTRINGTAG(type, tag, expected) \ | 13995 #define TEST_TOSTRINGTAG(type, tag, expected) \ |
13996 do { \ | 13996 do { \ |
13997 object = CompileRun("new " #type "()"); \ | 13997 object = CompileRun("new " #type "()"); \ |
13998 object.As<v8::Object>()->Set(toStringTag, v8_str(#tag)); \ | 13998 object.As<v8::Object>()->Set(toStringTag, v8_str(#tag)); \ |
13999 value = object.As<v8::Object>()->ObjectProtoToString(); \ | 13999 value = object.As<v8::Object>()->ObjectProtoToString(); \ |
14000 CHECK(value->IsString() && \ | 14000 CHECK(value->IsString() && \ |
14001 value->Equals(v8_str("[object " #expected "]"))); \ | 14001 value->Equals(v8_str("[object " #expected "]"))); \ |
14002 } while (0) | 14002 } while (0) |
14003 | 14003 |
14004 TEST_TOSTRINGTAG(Array, Object, Object); | 14004 TEST_TOSTRINGTAG(Array, Object, Object); |
14005 TEST_TOSTRINGTAG(Object, Arguments, ~Arguments); | 14005 TEST_TOSTRINGTAG(Object, Arguments, Arguments); |
14006 TEST_TOSTRINGTAG(Object, Array, ~Array); | 14006 TEST_TOSTRINGTAG(Object, Array, Array); |
14007 TEST_TOSTRINGTAG(Object, Boolean, ~Boolean); | 14007 TEST_TOSTRINGTAG(Object, Boolean, Boolean); |
14008 TEST_TOSTRINGTAG(Object, Date, ~Date); | 14008 TEST_TOSTRINGTAG(Object, Date, Date); |
14009 TEST_TOSTRINGTAG(Object, Error, ~Error); | 14009 TEST_TOSTRINGTAG(Object, Error, Error); |
14010 TEST_TOSTRINGTAG(Object, Function, ~Function); | 14010 TEST_TOSTRINGTAG(Object, Function, Function); |
14011 TEST_TOSTRINGTAG(Object, Number, ~Number); | 14011 TEST_TOSTRINGTAG(Object, Number, Number); |
14012 TEST_TOSTRINGTAG(Object, RegExp, ~RegExp); | 14012 TEST_TOSTRINGTAG(Object, RegExp, RegExp); |
14013 TEST_TOSTRINGTAG(Object, String, ~String); | 14013 TEST_TOSTRINGTAG(Object, String, String); |
14014 TEST_TOSTRINGTAG(Object, Foo, Foo); | 14014 TEST_TOSTRINGTAG(Object, Foo, Foo); |
14015 | 14015 |
14016 #undef TEST_TOSTRINGTAG | 14016 #undef TEST_TOSTRINGTAG |
14017 | 14017 |
| 14018 Local<v8::RegExp> valueRegExp = v8::RegExp::New(v8_str("^$"), |
| 14019 v8::RegExp::kNone); |
| 14020 Local<Value> valueNumber = v8_num(123); |
| 14021 Local<v8::Symbol> valueSymbol = v8_symbol("TestSymbol"); |
| 14022 Local<v8::Function> valueFunction = |
| 14023 CompileRun("function fn() {}").As<v8::Function>(); |
| 14024 Local<v8::Object> valueObject = v8::Object::New(v8::Isolate::GetCurrent()); |
| 14025 Local<v8::Primitive> valueNull = v8::Null(v8::Isolate::GetCurrent()); |
| 14026 Local<v8::Primitive> valueUndef = v8::Undefined(v8::Isolate::GetCurrent()); |
| 14027 |
| 14028 #define TEST_TOSTRINGTAG(type, tagValue, expected) \ |
| 14029 do { \ |
| 14030 object = CompileRun("new " #type "()"); \ |
| 14031 object.As<v8::Object>()->Set(toStringTag, tagValue); \ |
| 14032 value = object.As<v8::Object>()->ObjectProtoToString(); \ |
| 14033 CHECK(value->IsString() && \ |
| 14034 value->Equals(v8_str("[object " #expected "]"))); \ |
| 14035 } while (0) |
| 14036 |
| 14037 #define TEST_TOSTRINGTAG_TYPES(tagValue) \ |
| 14038 TEST_TOSTRINGTAG(Array, tagValue, Array); \ |
| 14039 TEST_TOSTRINGTAG(Object, tagValue, Object); \ |
| 14040 TEST_TOSTRINGTAG(Function, tagValue, Function); \ |
| 14041 TEST_TOSTRINGTAG(Date, tagValue, Date); \ |
| 14042 TEST_TOSTRINGTAG(RegExp, tagValue, RegExp); \ |
| 14043 TEST_TOSTRINGTAG(Error, tagValue, Error); \ |
| 14044 |
| 14045 // Test non-String-valued @@toStringTag |
| 14046 TEST_TOSTRINGTAG_TYPES(valueRegExp); |
| 14047 TEST_TOSTRINGTAG_TYPES(valueNumber); |
| 14048 TEST_TOSTRINGTAG_TYPES(valueSymbol); |
| 14049 TEST_TOSTRINGTAG_TYPES(valueFunction); |
| 14050 TEST_TOSTRINGTAG_TYPES(valueObject); |
| 14051 TEST_TOSTRINGTAG_TYPES(valueNull); |
| 14052 TEST_TOSTRINGTAG_TYPES(valueUndef); |
| 14053 |
| 14054 #undef TEST_TOSTRINGTAG |
| 14055 #undef TEST_TOSTRINGTAG_TYPES |
| 14056 |
14018 // @@toStringTag getter throws | 14057 // @@toStringTag getter throws |
14019 Local<Value> obj = v8::Object::New(isolate); | 14058 Local<Value> obj = v8::Object::New(isolate); |
14020 obj.As<v8::Object>()->SetAccessor(toStringTag, ThrowingSymbolAccessorGetter); | 14059 obj.As<v8::Object>()->SetAccessor(toStringTag, ThrowingSymbolAccessorGetter); |
14021 { | 14060 { |
14022 TryCatch try_catch; | 14061 TryCatch try_catch; |
14023 value = obj.As<v8::Object>()->ObjectProtoToString(); | 14062 value = obj.As<v8::Object>()->ObjectProtoToString(); |
14024 CHECK(value.IsEmpty()); | 14063 CHECK(value.IsEmpty()); |
14025 CHECK(try_catch.HasCaught()); | 14064 CHECK(try_catch.HasCaught()); |
14026 } | 14065 } |
14027 | 14066 |
(...skipping 10823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24851 "bar2.js"); | 24890 "bar2.js"); |
24852 } | 24891 } |
24853 | 24892 |
24854 | 24893 |
24855 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { | 24894 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { |
24856 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", | 24895 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", |
24857 " sourceMappingURL=bar2.js\n", "foo();", NULL}; | 24896 " sourceMappingURL=bar2.js\n", "foo();", NULL}; |
24858 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, | 24897 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, |
24859 "bar2.js"); | 24898 "bar2.js"); |
24860 } | 24899 } |
OLD | NEW |