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

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

Issue 483173002: Expose well-known Symbols to C++ API. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 4 months 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
« no previous file with comments | « src/heap/heap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2906 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 v8::Local<v8::Symbol> sym = v8::Symbol::New(isolate, name); 2917 v8::Local<v8::Symbol> sym = v8::Symbol::New(isolate, name);
2918 CHECK(!sym->SameValue(glob)); 2918 CHECK(!sym->SameValue(glob));
2919 2919
2920 CompileRun("var sym2 = Symbol.for('my-symbol')"); 2920 CompileRun("var sym2 = Symbol.for('my-symbol')");
2921 v8::Local<Value> sym2 = env->Global()->Get(v8_str("sym2")); 2921 v8::Local<Value> sym2 = env->Global()->Get(v8_str("sym2"));
2922 CHECK(sym2->SameValue(glob)); 2922 CHECK(sym2->SameValue(glob));
2923 CHECK(!sym2->SameValue(glob_api)); 2923 CHECK(!sym2->SameValue(glob_api));
2924 } 2924 }
2925 2925
2926 2926
2927 static void CheckWellKnownSymbol(v8::Local<v8::Symbol>(*getter)(v8::Isolate*),
2928 const char* name) {
2929 LocalContext env;
2930 v8::Isolate* isolate = env->GetIsolate();
2931 v8::HandleScope scope(isolate);
2932
2933 v8::Local<v8::Symbol> symbol = getter(isolate);
2934 std::string script = std::string("var sym = ") + name;
2935 CompileRun(script.c_str());
2936 v8::Local<Value> value = env->Global()->Get(v8_str("sym"));
2937
2938 CHECK(!value.IsEmpty());
2939 CHECK(!symbol.IsEmpty());
2940 CHECK(value->SameValue(symbol));
2941 }
2942
2943
2944 THREADED_TEST(WellKnownSymbols) {
2945 CheckWellKnownSymbol(v8::Symbol::GetIterator, "Symbol.iterator");
2946 CheckWellKnownSymbol(v8::Symbol::GetUnscopables, "Symbol.unscopables");
2947 }
2948
2949
2927 THREADED_TEST(GlobalPrivates) { 2950 THREADED_TEST(GlobalPrivates) {
2928 LocalContext env; 2951 LocalContext env;
2929 v8::Isolate* isolate = env->GetIsolate(); 2952 v8::Isolate* isolate = env->GetIsolate();
2930 v8::HandleScope scope(isolate); 2953 v8::HandleScope scope(isolate);
2931 2954
2932 v8::Local<String> name = v8_str("my-private"); 2955 v8::Local<String> name = v8_str("my-private");
2933 v8::Local<v8::Private> glob = v8::Private::ForApi(isolate, name); 2956 v8::Local<v8::Private> glob = v8::Private::ForApi(isolate, name);
2934 v8::Local<v8::Object> obj = v8::Object::New(isolate); 2957 v8::Local<v8::Object> obj = v8::Object::New(isolate);
2935 CHECK(obj->SetPrivate(glob, v8::Integer::New(isolate, 3))); 2958 CHECK(obj->SetPrivate(glob, v8::Integer::New(isolate, 3)));
2936 2959
(...skipping 19939 matching lines...) Expand 10 before | Expand all | Expand 10 after
22876 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); 22899 desc = x->GetOwnPropertyDescriptor(v8_str("p1"));
22877 Local<Function> set = 22900 Local<Function> set =
22878 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); 22901 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set")));
22879 Local<Function> get = 22902 Local<Function> get =
22880 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); 22903 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get")));
22881 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); 22904 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL));
22882 Handle<Value> args[] = { v8_num(14) }; 22905 Handle<Value> args[] = { v8_num(14) };
22883 set->Call(x, 1, args); 22906 set->Call(x, 1, args);
22884 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); 22907 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL));
22885 } 22908 }
OLDNEW
« no previous file with comments | « src/heap/heap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698