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

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

Issue 1428793002: Reland v8::Private and related APIs (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 1 month 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
OLDNEW
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 2430 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate); 2441 v8::Local<v8::FunctionTemplate> foo = v8::FunctionTemplate::New(isolate);
2442 v8::Local<v8::Name> name = v8::Symbol::New(isolate); 2442 v8::Local<v8::Name> name = v8::Symbol::New(isolate);
2443 CHECK(!name.IsEmpty()); 2443 CHECK(!name.IsEmpty());
2444 foo->PrototypeTemplate()->Set(name, v8::FunctionTemplate::New(isolate)); 2444 foo->PrototypeTemplate()->Set(name, v8::FunctionTemplate::New(isolate));
2445 v8::Local<v8::Object> new_instance = foo->InstanceTemplate()->NewInstance(); 2445 v8::Local<v8::Object> new_instance = foo->InstanceTemplate()->NewInstance();
2446 CHECK(!new_instance.IsEmpty()); 2446 CHECK(!new_instance.IsEmpty());
2447 CHECK(new_instance->Has(name)); 2447 CHECK(new_instance->Has(name));
2448 } 2448 }
2449 2449
2450 2450
2451 THREADED_TEST(PrivateProperties) {
2452 LocalContext env;
2453 v8::Isolate* isolate = env->GetIsolate();
2454 v8::HandleScope scope(isolate);
2455
2456 v8::Local<v8::Object> obj = v8::Object::New(isolate);
2457 v8::Local<v8::Private> priv1 = v8::Private::New(isolate);
2458 v8::Local<v8::Private> priv2 =
2459 v8::Private::New(isolate, v8_str("my-private"));
2460
2461 CcTest::heap()->CollectAllGarbage();
2462
2463 CHECK(priv2->Name()->Equals(v8::String::NewFromUtf8(isolate, "my-private")));
2464
2465 // Make sure delete of a non-existent private symbol property works.
2466 obj->DeletePrivate(env.local(), priv1).FromJust();
2467 CHECK(!obj->HasPrivate(env.local(), priv1).FromJust());
2468
2469 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 1503))
2470 .FromJust());
2471 CHECK(obj->HasPrivate(env.local(), priv1).FromJust());
2472 CHECK_EQ(1503,
2473 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value());
2474 CHECK(obj->SetPrivate(env.local(), priv1, v8::Integer::New(isolate, 2002))
2475 .FromJust());
2476 CHECK(obj->HasPrivate(env.local(), priv1).FromJust());
2477 CHECK_EQ(2002,
2478 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value());
2479
2480 CHECK_EQ(0u, obj->GetOwnPropertyNames()->Length());
2481 unsigned num_props = obj->GetPropertyNames()->Length();
2482 CHECK(obj->Set(v8::String::NewFromUtf8(isolate, "bla"),
2483 v8::Integer::New(isolate, 20)));
2484 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length());
2485 CHECK_EQ(num_props + 1, obj->GetPropertyNames()->Length());
2486
2487 CcTest::heap()->CollectAllGarbage();
2488
2489 // Add another property and delete it afterwards to force the object in
2490 // slow case.
2491 CHECK(obj->SetPrivate(env.local(), priv2, v8::Integer::New(isolate, 2008))
2492 .FromJust());
2493 CHECK_EQ(2002,
2494 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value());
2495 CHECK_EQ(2008,
2496 obj->GetPrivate(env.local(), priv2).ToLocalChecked()->Int32Value());
2497 CHECK_EQ(2002,
2498 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value());
2499 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length());
2500
2501 CHECK(obj->HasPrivate(env.local(), priv1).FromJust());
2502 CHECK(obj->HasPrivate(env.local(), priv2).FromJust());
2503 CHECK(obj->DeletePrivate(env.local(), priv2).FromJust());
2504 CHECK(obj->HasPrivate(env.local(), priv1).FromJust());
2505 CHECK(!obj->HasPrivate(env.local(), priv2).FromJust());
2506 CHECK_EQ(2002,
2507 obj->GetPrivate(env.local(), priv1).ToLocalChecked()->Int32Value());
2508 CHECK_EQ(1u, obj->GetOwnPropertyNames()->Length());
2509
2510 // Private properties are not inherited (for the time being).
2511 v8::Local<v8::Object> child = v8::Object::New(isolate);
2512 child->SetPrototype(obj);
2513 CHECK(!child->HasPrivate(env.local(), priv1).FromJust());
2514 CHECK_EQ(0u, child->GetOwnPropertyNames()->Length());
2515 }
2516
2517
2451 THREADED_TEST(GlobalSymbols) { 2518 THREADED_TEST(GlobalSymbols) {
2452 LocalContext env; 2519 LocalContext env;
2453 v8::Isolate* isolate = env->GetIsolate(); 2520 v8::Isolate* isolate = env->GetIsolate();
2454 v8::HandleScope scope(isolate); 2521 v8::HandleScope scope(isolate);
2455 2522
2456 v8::Local<String> name = v8_str("my-symbol"); 2523 v8::Local<String> name = v8_str("my-symbol");
2457 v8::Local<v8::Symbol> glob = v8::Symbol::For(isolate, name); 2524 v8::Local<v8::Symbol> glob = v8::Symbol::For(isolate, name);
2458 v8::Local<v8::Symbol> glob2 = v8::Symbol::For(isolate, name); 2525 v8::Local<v8::Symbol> glob2 = v8::Symbol::For(isolate, name);
2459 CHECK(glob2->SameValue(glob)); 2526 CHECK(glob2->SameValue(glob));
2460 2527
(...skipping 28 matching lines...) Expand all
2489 CHECK(value->SameValue(symbol)); 2556 CHECK(value->SameValue(symbol));
2490 } 2557 }
2491 2558
2492 2559
2493 THREADED_TEST(WellKnownSymbols) { 2560 THREADED_TEST(WellKnownSymbols) {
2494 CheckWellKnownSymbol(v8::Symbol::GetIterator, "Symbol.iterator"); 2561 CheckWellKnownSymbol(v8::Symbol::GetIterator, "Symbol.iterator");
2495 CheckWellKnownSymbol(v8::Symbol::GetUnscopables, "Symbol.unscopables"); 2562 CheckWellKnownSymbol(v8::Symbol::GetUnscopables, "Symbol.unscopables");
2496 } 2563 }
2497 2564
2498 2565
2566 THREADED_TEST(GlobalPrivates) {
2567 i::FLAG_allow_natives_syntax = true;
2568 LocalContext env;
2569 v8::Isolate* isolate = env->GetIsolate();
2570 v8::HandleScope scope(isolate);
2571
2572 v8::Local<String> name = v8_str("my-private");
2573 v8::Local<v8::Private> glob = v8::Private::ForApi(isolate, name);
2574 v8::Local<v8::Object> obj = v8::Object::New(isolate);
2575 CHECK(obj->SetPrivate(env.local(), glob, v8::Integer::New(isolate, 3))
2576 .FromJust());
2577
2578 v8::Local<v8::Private> glob2 = v8::Private::ForApi(isolate, name);
2579 CHECK(obj->HasPrivate(env.local(), glob2).FromJust());
2580
2581 v8::Local<v8::Private> priv = v8::Private::New(isolate, name);
2582 CHECK(!obj->HasPrivate(env.local(), priv).FromJust());
2583
2584 CompileRun("var intern = %CreatePrivateSymbol('my-private')");
2585 v8::Local<Value> intern = env->Global()->Get(v8_str("intern"));
2586 CHECK(!obj->Has(intern));
2587 }
2588
2589
2499 class ScopedArrayBufferContents { 2590 class ScopedArrayBufferContents {
2500 public: 2591 public:
2501 explicit ScopedArrayBufferContents(const v8::ArrayBuffer::Contents& contents) 2592 explicit ScopedArrayBufferContents(const v8::ArrayBuffer::Contents& contents)
2502 : contents_(contents) {} 2593 : contents_(contents) {}
2503 ~ScopedArrayBufferContents() { free(contents_.Data()); } 2594 ~ScopedArrayBufferContents() { free(contents_.Data()); }
2504 void* Data() const { return contents_.Data(); } 2595 void* Data() const { return contents_.Data(); }
2505 size_t ByteLength() const { return contents_.ByteLength(); } 2596 size_t ByteLength() const { return contents_.ByteLength(); }
2506 2597
2507 private: 2598 private:
2508 const v8::ArrayBuffer::Contents contents_; 2599 const v8::ArrayBuffer::Contents contents_;
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
2908 CHECK_EQ(0xDD, result->Int32Value()); 2999 CHECK_EQ(0xDD, result->Int32Value());
2909 } 3000 }
2910 3001
2911 3002
2912 THREADED_TEST(HiddenProperties) { 3003 THREADED_TEST(HiddenProperties) {
2913 LocalContext env; 3004 LocalContext env;
2914 v8::Isolate* isolate = env->GetIsolate(); 3005 v8::Isolate* isolate = env->GetIsolate();
2915 v8::HandleScope scope(isolate); 3006 v8::HandleScope scope(isolate);
2916 3007
2917 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 3008 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
2918 v8::Local<v8::String> key = v8_str("api-test::hidden-key"); 3009 v8::Local<v8::Private> key =
3010 v8::Private::ForApi(isolate, v8_str("api-test::hidden-key"));
2919 v8::Local<v8::String> empty = v8_str(""); 3011 v8::Local<v8::String> empty = v8_str("");
2920 v8::Local<v8::String> prop_name = v8_str("prop_name"); 3012 v8::Local<v8::String> prop_name = v8_str("prop_name");
2921 3013
2922 CcTest::heap()->CollectAllGarbage(); 3014 CcTest::heap()->CollectAllGarbage();
2923 3015
2924 // Make sure delete of a non-existent hidden value works 3016 // Make sure delete of a non-existent hidden value works
2925 CHECK(obj->DeleteHiddenValue(key)); 3017 obj->DeletePrivate(env.local(), key).FromJust();
2926 3018
2927 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 1503))); 3019 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 1503))
2928 CHECK_EQ(1503, obj->GetHiddenValue(key)->Int32Value()); 3020 .FromJust());
2929 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002))); 3021 CHECK_EQ(1503,
2930 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3022 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
3023 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002))
3024 .FromJust());
3025 CHECK_EQ(2002,
3026 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
2931 3027
2932 CcTest::heap()->CollectAllGarbage(); 3028 CcTest::heap()->CollectAllGarbage();
2933 3029
2934 // Make sure we do not find the hidden property. 3030 // Make sure we do not find the hidden property.
2935 CHECK(!obj->Has(empty)); 3031 CHECK(!obj->Has(empty));
2936 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3032 CHECK_EQ(2002,
3033 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
2937 CHECK(obj->Get(empty)->IsUndefined()); 3034 CHECK(obj->Get(empty)->IsUndefined());
2938 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3035 CHECK_EQ(2002,
3036 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
2939 CHECK(obj->Set(empty, v8::Integer::New(isolate, 2003))); 3037 CHECK(obj->Set(empty, v8::Integer::New(isolate, 2003)));
2940 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3038 CHECK_EQ(2002,
3039 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
2941 CHECK_EQ(2003, obj->Get(empty)->Int32Value()); 3040 CHECK_EQ(2003, obj->Get(empty)->Int32Value());
2942 3041
2943 CcTest::heap()->CollectAllGarbage(); 3042 CcTest::heap()->CollectAllGarbage();
2944 3043
2945 // Add another property and delete it afterwards to force the object in 3044 // Add another property and delete it afterwards to force the object in
2946 // slow case. 3045 // slow case.
2947 CHECK(obj->Set(prop_name, v8::Integer::New(isolate, 2008))); 3046 CHECK(obj->Set(prop_name, v8::Integer::New(isolate, 2008)));
2948 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3047 CHECK_EQ(2002,
3048 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
2949 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value()); 3049 CHECK_EQ(2008, obj->Get(prop_name)->Int32Value());
2950 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3050 CHECK_EQ(2002,
3051 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
2951 CHECK(obj->Delete(prop_name)); 3052 CHECK(obj->Delete(prop_name));
2952 CHECK_EQ(2002, obj->GetHiddenValue(key)->Int32Value()); 3053 CHECK_EQ(2002,
3054 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
2953 3055
2954 CcTest::heap()->CollectAllGarbage(); 3056 CcTest::heap()->CollectAllGarbage();
2955 3057
2956 CHECK(obj->SetHiddenValue(key, Handle<Value>())); 3058 CHECK(obj->SetPrivate(env.local(), key, v8::Integer::New(isolate, 2002))
2957 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3059 .FromJust());
2958 3060 CHECK(obj->DeletePrivate(env.local(), key).FromJust());
2959 CHECK(obj->SetHiddenValue(key, v8::Integer::New(isolate, 2002))); 3061 CHECK(!obj->HasPrivate(env.local(), key).FromJust());
2960 CHECK(obj->DeleteHiddenValue(key));
2961 CHECK(obj->GetHiddenValue(key).IsEmpty());
2962 } 3062 }
2963 3063
2964 3064
2965 THREADED_TEST(Regress97784) { 3065 THREADED_TEST(Regress97784) {
2966 // Regression test for crbug.com/97784 3066 // Regression test for crbug.com/97784
2967 // Messing with the Object.prototype should not have effect on 3067 // Messing with the Object.prototype should not have effect on
2968 // hidden properties. 3068 // hidden properties.
2969 LocalContext env; 3069 LocalContext env;
2970 v8::HandleScope scope(env->GetIsolate()); 3070 v8::HandleScope scope(env->GetIsolate());
2971 3071
2972 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate()); 3072 v8::Local<v8::Object> obj = v8::Object::New(env->GetIsolate());
2973 v8::Local<v8::String> key = v8_str("hidden"); 3073 v8::Local<v8::Private> key =
3074 v8::Private::New(env->GetIsolate(), v8_str("hidden"));
2974 3075
2975 CompileRun( 3076 CompileRun(
2976 "set_called = false;" 3077 "set_called = false;"
2977 "Object.defineProperty(" 3078 "Object.defineProperty("
2978 " Object.prototype," 3079 " Object.prototype,"
2979 " 'hidden'," 3080 " 'hidden',"
2980 " {get: function() { return 45; }," 3081 " {get: function() { return 45; },"
2981 " set: function() { set_called = true; }})"); 3082 " set: function() { set_called = true; }})");
2982 3083
2983 CHECK(obj->GetHiddenValue(key).IsEmpty()); 3084 CHECK(!obj->HasPrivate(env.local(), key).FromJust());
2984 // Make sure that the getter and setter from Object.prototype is not invoked. 3085 // Make sure that the getter and setter from Object.prototype is not invoked.
2985 // If it did we would have full access to the hidden properties in 3086 // If it did we would have full access to the hidden properties in
2986 // the accessor. 3087 // the accessor.
2987 CHECK(obj->SetHiddenValue(key, v8::Integer::New(env->GetIsolate(), 42))); 3088 CHECK(
3089 obj->SetPrivate(env.local(), key, v8::Integer::New(env->GetIsolate(), 42))
3090 .FromJust());
2988 ExpectFalse("set_called"); 3091 ExpectFalse("set_called");
2989 CHECK_EQ(42, obj->GetHiddenValue(key)->Int32Value()); 3092 CHECK_EQ(42,
3093 obj->GetPrivate(env.local(), key).ToLocalChecked()->Int32Value());
2990 } 3094 }
2991 3095
2992 3096
2993 THREADED_TEST(External) { 3097 THREADED_TEST(External) {
2994 v8::HandleScope scope(CcTest::isolate()); 3098 v8::HandleScope scope(CcTest::isolate());
2995 int x = 3; 3099 int x = 3;
2996 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x); 3100 Local<v8::External> ext = v8::External::New(CcTest::isolate(), &x);
2997 LocalContext env; 3101 LocalContext env;
2998 env->Global()->Set(v8_str("ext"), ext); 3102 env->Global()->Set(v8_str("ext"), ext);
2999 Local<Value> reext_obj = CompileRun("this.ext"); 3103 Local<Value> reext_obj = CompileRun("this.ext");
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
4072 // clear out the message listener 4176 // clear out the message listener
4073 v8::V8::RemoveMessageListeners(check_message_1); 4177 v8::V8::RemoveMessageListeners(check_message_1);
4074 } 4178 }
4075 4179
4076 4180
4077 static void check_message_2(v8::Handle<v8::Message> message, 4181 static void check_message_2(v8::Handle<v8::Message> message,
4078 v8::Handle<Value> data) { 4182 v8::Handle<Value> data) {
4079 LocalContext context; 4183 LocalContext context;
4080 CHECK(data->IsObject()); 4184 CHECK(data->IsObject());
4081 v8::Local<v8::Value> hidden_property = 4185 v8::Local<v8::Value> hidden_property =
4082 v8::Object::Cast(*data)->GetHiddenValue(v8_str("hidden key")); 4186 v8::Object::Cast(*data)
4187 ->GetPrivate(
4188 context.local(),
4189 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key")))
4190 .ToLocalChecked();
4083 CHECK(v8_str("hidden value")->Equals(hidden_property)); 4191 CHECK(v8_str("hidden value")->Equals(hidden_property));
4084 CHECK(!message->IsSharedCrossOrigin()); 4192 CHECK(!message->IsSharedCrossOrigin());
4085 message_received = true; 4193 message_received = true;
4086 } 4194 }
4087 4195
4088 4196
4089 TEST(MessageHandler2) { 4197 TEST(MessageHandler2) {
4090 message_received = false; 4198 message_received = false;
4091 v8::HandleScope scope(CcTest::isolate()); 4199 v8::HandleScope scope(CcTest::isolate());
4092 CHECK(!message_received); 4200 CHECK(!message_received);
4093 v8::V8::AddMessageListener(check_message_2); 4201 v8::V8::AddMessageListener(check_message_2);
4094 LocalContext context; 4202 LocalContext context;
4095 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error")); 4203 v8::Local<v8::Value> error = v8::Exception::Error(v8_str("custom error"));
4096 v8::Object::Cast(*error) 4204 v8::Object::Cast(*error)
4097 ->SetHiddenValue(v8_str("hidden key"), v8_str("hidden value")); 4205 ->SetPrivate(context.local(),
4206 v8::Private::ForApi(CcTest::isolate(), v8_str("hidden key")),
4207 v8_str("hidden value"))
4208 .FromJust();
4098 context->Global()->Set(v8_str("error"), error); 4209 context->Global()->Set(v8_str("error"), error);
4099 CompileRun("throw error;"); 4210 CompileRun("throw error;");
4100 CHECK(message_received); 4211 CHECK(message_received);
4101 // clear out the message listener 4212 // clear out the message listener
4102 v8::V8::RemoveMessageListeners(check_message_2); 4213 v8::V8::RemoveMessageListeners(check_message_2);
4103 } 4214 }
4104 4215
4105 4216
4106 static void check_message_3(v8::Handle<v8::Message> message, 4217 static void check_message_3(v8::Handle<v8::Message> message,
4107 v8::Handle<Value> data) { 4218 v8::Handle<Value> data) {
(...skipping 5373 matching lines...) Expand 10 before | Expand all | Expand 10 after
9481 // Inherit from t1 and mark prototype as hidden. 9592 // Inherit from t1 and mark prototype as hidden.
9482 t2->Inherit(t1); 9593 t2->Inherit(t1);
9483 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4)); 9594 t2->InstanceTemplate()->Set(v8_str("mine"), v8_num(4));
9484 9595
9485 Local<v8::Object> o2 = t2->GetFunction()->NewInstance(); 9596 Local<v8::Object> o2 = t2->GetFunction()->NewInstance();
9486 CHECK(o2->SetPrototype(o1)); 9597 CHECK(o2->SetPrototype(o1));
9487 9598
9488 v8::Local<v8::Symbol> sym = 9599 v8::Local<v8::Symbol> sym =
9489 v8::Symbol::New(context->GetIsolate(), v8_str("s1")); 9600 v8::Symbol::New(context->GetIsolate(), v8_str("s1"));
9490 o1->Set(sym, v8_num(3)); 9601 o1->Set(sym, v8_num(3));
9491 o1->SetHiddenValue( 9602 o1->SetPrivate(context.local(),
9492 v8_str("h1"), v8::Integer::New(context->GetIsolate(), 2013)); 9603 v8::Private::New(context->GetIsolate(), v8_str("h1")),
9604 v8::Integer::New(context->GetIsolate(), 2013))
9605 .FromJust();
9493 9606
9494 // Call the runtime version of GetOwnPropertyNames() on 9607 // Call the runtime version of GetOwnPropertyNames() on
9495 // the natively created object through JavaScript. 9608 // the natively created object through JavaScript.
9496 context->Global()->Set(v8_str("obj"), o2); 9609 context->Global()->Set(v8_str("obj"), o2);
9497 context->Global()->Set(v8_str("sym"), sym); 9610 context->Global()->Set(v8_str("sym"), sym);
9498 // PROPERTY_ATTRIBUTES_NONE = 0 9611 // PROPERTY_ATTRIBUTES_NONE = 0
9499 CompileRun("var names = %GetOwnPropertyNames(obj, 0);"); 9612 CompileRun("var names = %GetOwnPropertyNames(obj, 0);");
9500 9613
9501 ExpectInt32("names.length", 7); 9614 ExpectInt32("names.length", 7);
9502 ExpectTrue("names.indexOf(\"foo\") >= 0"); 9615 ExpectTrue("names.indexOf(\"foo\") >= 0");
(...skipping 9491 matching lines...) Expand 10 before | Expand all | Expand 10 after
18994 } 19107 }
18995 19108
18996 19109
18997 THREADED_TEST(Regress157124) { 19110 THREADED_TEST(Regress157124) {
18998 LocalContext context; 19111 LocalContext context;
18999 v8::Isolate* isolate = context->GetIsolate(); 19112 v8::Isolate* isolate = context->GetIsolate();
19000 v8::HandleScope scope(isolate); 19113 v8::HandleScope scope(isolate);
19001 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 19114 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
19002 Local<Object> obj = templ->NewInstance(); 19115 Local<Object> obj = templ->NewInstance();
19003 obj->GetIdentityHash(); 19116 obj->GetIdentityHash();
19004 obj->DeleteHiddenValue(v8_str("Bug")); 19117 obj->DeletePrivate(context.local(),
19118 v8::Private::ForApi(isolate, v8_str("Bug")))
19119 .FromJust();
19005 } 19120 }
19006 19121
19007 19122
19008 THREADED_TEST(Regress2535) { 19123 THREADED_TEST(Regress2535) {
19009 LocalContext context; 19124 LocalContext context;
19010 v8::HandleScope scope(context->GetIsolate()); 19125 v8::HandleScope scope(context->GetIsolate());
19011 Local<Value> set_value = CompileRun("new Set();"); 19126 Local<Value> set_value = CompileRun("new Set();");
19012 Local<Object> set_object(Local<Object>::Cast(set_value)); 19127 Local<Object> set_object(Local<Object>::Cast(set_value));
19013 CHECK_EQ(0, set_object->InternalFieldCount()); 19128 CHECK_EQ(0, set_object->InternalFieldCount());
19014 Local<Value> map_value = CompileRun("new Map();"); 19129 Local<Value> map_value = CompileRun("new Map();");
19015 Local<Object> map_object(Local<Object>::Cast(map_value)); 19130 Local<Object> map_object(Local<Object>::Cast(map_value));
19016 CHECK_EQ(0, map_object->InternalFieldCount()); 19131 CHECK_EQ(0, map_object->InternalFieldCount());
19017 } 19132 }
19018 19133
19019 19134
19020 THREADED_TEST(Regress2746) { 19135 THREADED_TEST(Regress2746) {
19021 LocalContext context; 19136 LocalContext context;
19022 v8::Isolate* isolate = context->GetIsolate(); 19137 v8::Isolate* isolate = context->GetIsolate();
19023 v8::HandleScope scope(isolate); 19138 v8::HandleScope scope(isolate);
19024 Local<Object> obj = Object::New(isolate); 19139 Local<Object> obj = Object::New(isolate);
19025 Local<String> key = String::NewFromUtf8(context->GetIsolate(), "key"); 19140 Local<v8::Private> key = v8::Private::New(isolate, v8_str("key"));
19026 obj->SetHiddenValue(key, v8::Undefined(isolate)); 19141 CHECK(
19027 Local<Value> value = obj->GetHiddenValue(key); 19142 obj->SetPrivate(context.local(), key, v8::Undefined(isolate)).FromJust());
19143 Local<Value> value = obj->GetPrivate(context.local(), key).ToLocalChecked();
19028 CHECK(!value.IsEmpty()); 19144 CHECK(!value.IsEmpty());
19029 CHECK(value->IsUndefined()); 19145 CHECK(value->IsUndefined());
19030 } 19146 }
19031 19147
19032 19148
19033 THREADED_TEST(Regress260106) { 19149 THREADED_TEST(Regress260106) {
19034 LocalContext context; 19150 LocalContext context;
19035 v8::Isolate* isolate = context->GetIsolate(); 19151 v8::Isolate* isolate = context->GetIsolate();
19036 v8::HandleScope scope(isolate); 19152 v8::HandleScope scope(isolate);
19037 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate, 19153 Local<FunctionTemplate> templ = FunctionTemplate::New(isolate,
(...skipping 1474 matching lines...) Expand 10 before | Expand all | Expand 10 after
20512 v8::ObjectTemplate::New(isolate); 20628 v8::ObjectTemplate::New(isolate);
20513 object_template->SetAccessCheckCallback(AccessCounter); 20629 object_template->SetAccessCheckCallback(AccessCounter);
20514 20630
20515 v8::Handle<Context> context = Context::New(isolate); 20631 v8::Handle<Context> context = Context::New(isolate);
20516 v8::Context::Scope context_scope(context); 20632 v8::Context::Scope context_scope(context);
20517 20633
20518 v8::Handle<v8::Object> obj = object_template->NewInstance(); 20634 v8::Handle<v8::Object> obj = object_template->NewInstance();
20519 obj->Set(v8_str("key"), v8_str("value")); 20635 obj->Set(v8_str("key"), v8_str("value"));
20520 obj->Delete(v8_str("key")); 20636 obj->Delete(v8_str("key"));
20521 20637
20522 obj->SetHiddenValue(v8_str("hidden key 2"), v8_str("hidden value 2")); 20638 obj->SetPrivate(context, v8::Private::New(isolate, v8_str("hidden key 2")),
20639 v8_str("hidden value 2"))
20640 .FromJust();
20523 } 20641 }
20524 20642
20525 20643
20526 TEST(Regress411793) { 20644 TEST(Regress411793) {
20527 v8::Isolate* isolate = CcTest::isolate(); 20645 v8::Isolate* isolate = CcTest::isolate();
20528 v8::HandleScope handle_scope(isolate); 20646 v8::HandleScope handle_scope(isolate);
20529 v8::Handle<v8::ObjectTemplate> object_template = 20647 v8::Handle<v8::ObjectTemplate> object_template =
20530 v8::ObjectTemplate::New(isolate); 20648 v8::ObjectTemplate::New(isolate);
20531 object_template->SetAccessCheckCallback(AccessCounter); 20649 object_template->SetAccessCheckCallback(AccessCounter);
20532 20650
(...skipping 1423 matching lines...) Expand 10 before | Expand all | Expand 10 after
21956 env2->Global()->Set(v8_str("obj2"), object2); 22074 env2->Global()->Set(v8_str("obj2"), object2);
21957 ExpectString("typeof obj2.values", "function"); 22075 ExpectString("typeof obj2.values", "function");
21958 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values"))); 22076 CHECK_NE(*object->Get(v8_str("values")), *object2->Get(v8_str("values")));
21959 22077
21960 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values"))); 22078 auto values2 = Local<Function>::Cast(object2->Get(v8_str("values")));
21961 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2)); 22079 auto fn2 = i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*values2));
21962 auto ctx2 = v8::Utils::OpenHandle(*env2.local()); 22080 auto ctx2 = v8::Utils::OpenHandle(*env2.local());
21963 CHECK_EQ(fn2->GetCreationContext(), *ctx2); 22081 CHECK_EQ(fn2->GetCreationContext(), *ctx2);
21964 } 22082 }
21965 } 22083 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698