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 21929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21940 v8::HandleScope scope(isolate); | 21940 v8::HandleScope scope(isolate); |
21941 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate, | 21941 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate, |
21942 DummyCallHandler); | 21942 DummyCallHandler); |
21943 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); | 21943 CompileRun("for (var i = 0; i < 128; i++) Object.prototype[i] = 0;"); |
21944 Local<Function> function = | 21944 Local<Function> function = |
21945 templ->GetFunction(context.local()).ToLocalChecked(); | 21945 templ->GetFunction(context.local()).ToLocalChecked(); |
21946 CHECK(!function.IsEmpty()); | 21946 CHECK(!function.IsEmpty()); |
21947 CHECK(function->IsFunction()); | 21947 CHECK(function->IsFunction()); |
21948 } | 21948 } |
21949 | 21949 |
| 21950 THREADED_TEST(JSONParseObjectWithContext) { |
| 21951 LocalContext context; |
| 21952 HandleScope scope(context->GetIsolate()); |
| 21953 Local<Value> obj = |
| 21954 v8::JSON::Parse(context.local(), v8_str("{\"x\":42}")).ToLocalChecked(); |
| 21955 Local<Object> global = context->Global(); |
| 21956 global->Set(context.local(), v8_str("obj"), obj).FromJust(); |
| 21957 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); |
| 21958 } |
21950 | 21959 |
21951 THREADED_TEST(JSONParseObject) { | 21960 THREADED_TEST(JSONParseObject) { |
21952 LocalContext context; | 21961 LocalContext context; |
21953 HandleScope scope(context->GetIsolate()); | 21962 HandleScope scope(context->GetIsolate()); |
21954 Local<Value> obj = | 21963 Local<Value> obj = |
21955 v8::JSON::Parse(context->GetIsolate(), v8_str("{\"x\":42}")) | 21964 v8::JSON::Parse(context->GetIsolate(), v8_str("{\"x\":42}")) |
21956 .ToLocalChecked(); | 21965 .ToLocalChecked(); |
21957 Local<Object> global = context->Global(); | 21966 Local<Object> global = context->Global(); |
21958 global->Set(context.local(), v8_str("obj"), obj).FromJust(); | 21967 global->Set(context.local(), v8_str("obj"), obj).FromJust(); |
21959 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); | 21968 ExpectString("JSON.stringify(obj)", "{\"x\":42}"); |
21960 } | 21969 } |
21961 | 21970 |
21962 | 21971 |
21963 THREADED_TEST(JSONParseNumber) { | 21972 THREADED_TEST(JSONParseNumber) { |
21964 LocalContext context; | 21973 LocalContext context; |
21965 HandleScope scope(context->GetIsolate()); | 21974 HandleScope scope(context->GetIsolate()); |
21966 Local<Value> obj = | 21975 Local<Value> obj = |
21967 v8::JSON::Parse(context->GetIsolate(), v8_str("42")).ToLocalChecked(); | 21976 v8::JSON::Parse(context->GetIsolate(), v8_str("42")).ToLocalChecked(); |
21968 Local<Object> global = context->Global(); | 21977 Local<Object> global = context->Global(); |
21969 global->Set(context.local(), v8_str("obj"), obj).FromJust(); | 21978 global->Set(context.local(), v8_str("obj"), obj).FromJust(); |
21970 ExpectString("JSON.stringify(obj)", "42"); | 21979 ExpectString("JSON.stringify(obj)", "42"); |
21971 } | 21980 } |
21972 | 21981 |
| 21982 THREADED_TEST(JSONStringifyObject) { |
| 21983 LocalContext context; |
| 21984 HandleScope scope(context->GetIsolate()); |
| 21985 Local<Value> value = |
| 21986 v8::JSON::Parse(context->GetIsolate(), v8_str("{\"x\":42}")) |
| 21987 .ToLocalChecked(); |
| 21988 Local<Object> obj = value->ToObject(context.local()).ToLocalChecked(); |
| 21989 Local<Object> global = context->Global(); |
| 21990 global->Set(context.local(), v8_str("obj"), obj).FromJust(); |
| 21991 Local<String> json = |
| 21992 v8::JSON::Stringify(context->GetIsolate(), obj).ToLocalChecked(); |
| 21993 v8::String::Utf8Value utf8(json); |
| 21994 ExpectString("JSON.stringify(obj)", *utf8); |
| 21995 } |
21973 | 21996 |
21974 #if V8_OS_POSIX && !V8_OS_NACL | 21997 #if V8_OS_POSIX && !V8_OS_NACL |
21975 class ThreadInterruptTest { | 21998 class ThreadInterruptTest { |
21976 public: | 21999 public: |
21977 ThreadInterruptTest() : sem_(0), sem_value_(0) { } | 22000 ThreadInterruptTest() : sem_(0), sem_value_(0) { } |
21978 ~ThreadInterruptTest() {} | 22001 ~ThreadInterruptTest() {} |
21979 | 22002 |
21980 void RunTest() { | 22003 void RunTest() { |
21981 InterruptThread i_thread(this); | 22004 InterruptThread i_thread(this); |
21982 i_thread.Start(); | 22005 i_thread.Start(); |
(...skipping 2995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
24978 } | 25001 } |
24979 delete garbage; | 25002 delete garbage; |
24980 // Check that moderate memory pressure notification sets GC into memory | 25003 // Check that moderate memory pressure notification sets GC into memory |
24981 // optimizing mode. | 25004 // optimizing mode. |
24982 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kModerate); | 25005 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kModerate); |
24983 CHECK(CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage()); | 25006 CHECK(CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage()); |
24984 // Check that disabling memory pressure returns GC into normal mode. | 25007 // Check that disabling memory pressure returns GC into normal mode. |
24985 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kNone); | 25008 isolate->MemoryPressureNotification(v8::MemoryPressureLevel::kNone); |
24986 CHECK(!CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage()); | 25009 CHECK(!CcTest::i_isolate()->heap()->ShouldOptimizeForMemoryUsage()); |
24987 } | 25010 } |
OLD | NEW |