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

Side by Side Diff: src/api.cc

Issue 48923002: Provide private symbols through internal APIs (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Make privates a non-value; comments Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/api.h ('k') | src/array-iterator.js » ('j') | src/objects.h » ('J')
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 2754 matching lines...) Expand 10 before | Expand all | Expand 10 after
2765 void v8::String::CheckCast(v8::Value* that) { 2765 void v8::String::CheckCast(v8::Value* that) {
2766 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2766 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2767 ApiCheck(obj->IsString(), 2767 ApiCheck(obj->IsString(),
2768 "v8::String::Cast()", 2768 "v8::String::Cast()",
2769 "Could not convert to string"); 2769 "Could not convert to string");
2770 } 2770 }
2771 2771
2772 2772
2773 void v8::Symbol::CheckCast(v8::Value* that) { 2773 void v8::Symbol::CheckCast(v8::Value* that) {
2774 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2774 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2775 ApiCheck(obj->IsSymbol(), 2775 ApiCheck(obj->IsSymbol() && !obj->IsPrivate(),
2776 "v8::Symbol::Cast()", 2776 "v8::Symbol::Cast()",
2777 "Could not convert to symbol"); 2777 "Could not convert to symbol");
2778 } 2778 }
2779 2779
2780 2780
2781 void v8::Number::CheckCast(v8::Value* that) { 2781 void v8::Number::CheckCast(v8::Value* that) {
2782 i::Handle<i::Object> obj = Utils::OpenHandle(that); 2782 i::Handle<i::Object> obj = Utils::OpenHandle(that);
2783 ApiCheck(obj->IsNumber(), 2783 ApiCheck(obj->IsNumber(),
2784 "v8::Number::Cast()", 2784 "v8::Number::Cast()",
2785 "Could not convert to number"); 2785 "Could not convert to number");
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
3177 self, 3177 self,
3178 key_obj, 3178 key_obj,
3179 value_obj, 3179 value_obj,
3180 static_cast<PropertyAttributes>(attribs)); 3180 static_cast<PropertyAttributes>(attribs));
3181 has_pending_exception = obj.is_null(); 3181 has_pending_exception = obj.is_null();
3182 EXCEPTION_BAILOUT_CHECK(isolate, false); 3182 EXCEPTION_BAILOUT_CHECK(isolate, false);
3183 return true; 3183 return true;
3184 } 3184 }
3185 3185
3186 3186
3187 bool v8::Object::SetPrivate(v8::Handle<Private> key, v8::Handle<Value> value) {
3188 return Set(*reinterpret_cast<v8::Handle<Value>*>(&key), value, DontEnum);
3189 }
3190
3191
3187 bool v8::Object::ForceDelete(v8::Handle<Value> key) { 3192 bool v8::Object::ForceDelete(v8::Handle<Value> key) {
3188 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3193 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3189 ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false); 3194 ON_BAILOUT(isolate, "v8::Object::ForceDelete()", return false);
3190 ENTER_V8(isolate); 3195 ENTER_V8(isolate);
3191 i::HandleScope scope(isolate); 3196 i::HandleScope scope(isolate);
3192 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3197 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3193 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 3198 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3194 3199
3195 // When deleting a property on the global object using ForceDelete 3200 // When deleting a property on the global object using ForceDelete
3196 // deoptimize all functions as optimized code does not check for the hole 3201 // deoptimize all functions as optimized code does not check for the hole
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3228 ENTER_V8(isolate); 3233 ENTER_V8(isolate);
3229 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3234 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3230 EXCEPTION_PREAMBLE(isolate); 3235 EXCEPTION_PREAMBLE(isolate);
3231 i::Handle<i::Object> result = i::Object::GetElement(isolate, self, index); 3236 i::Handle<i::Object> result = i::Object::GetElement(isolate, self, index);
3232 has_pending_exception = result.is_null(); 3237 has_pending_exception = result.is_null();
3233 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); 3238 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
3234 return Utils::ToLocal(result); 3239 return Utils::ToLocal(result);
3235 } 3240 }
3236 3241
3237 3242
3243 Local<Value> v8::Object::GetPrivate(v8::Handle<Private> key) {
3244 return Get(*reinterpret_cast<v8::Handle<Value>*>(&key));
3245 }
3246
3247
3238 PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) { 3248 PropertyAttribute v8::Object::GetPropertyAttributes(v8::Handle<Value> key) {
3239 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3249 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3240 ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()", 3250 ON_BAILOUT(isolate, "v8::Object::GetPropertyAttribute()",
3241 return static_cast<PropertyAttribute>(NONE)); 3251 return static_cast<PropertyAttribute>(NONE));
3242 ENTER_V8(isolate); 3252 ENTER_V8(isolate);
3243 i::HandleScope scope(isolate); 3253 i::HandleScope scope(isolate);
3244 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3254 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3245 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 3255 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3246 if (!key_obj->IsName()) { 3256 if (!key_obj->IsName()) {
3247 EXCEPTION_PREAMBLE(isolate); 3257 EXCEPTION_PREAMBLE(isolate);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3427 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3437 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3428 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 3438 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3429 EXCEPTION_PREAMBLE(isolate); 3439 EXCEPTION_PREAMBLE(isolate);
3430 i::Handle<i::Object> obj = i::DeleteProperty(self, key_obj); 3440 i::Handle<i::Object> obj = i::DeleteProperty(self, key_obj);
3431 has_pending_exception = obj.is_null(); 3441 has_pending_exception = obj.is_null();
3432 EXCEPTION_BAILOUT_CHECK(isolate, false); 3442 EXCEPTION_BAILOUT_CHECK(isolate, false);
3433 return obj->IsTrue(); 3443 return obj->IsTrue();
3434 } 3444 }
3435 3445
3436 3446
3447 bool v8::Object::DeletePrivate(v8::Handle<Private> key) {
3448 return Delete(*reinterpret_cast<v8::Handle<Value>*>(&key));
3449 }
3450
3451
3437 bool v8::Object::Has(v8::Handle<Value> key) { 3452 bool v8::Object::Has(v8::Handle<Value> key) {
3438 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3453 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3439 ON_BAILOUT(isolate, "v8::Object::Has()", return false); 3454 ON_BAILOUT(isolate, "v8::Object::Has()", return false);
3440 ENTER_V8(isolate); 3455 ENTER_V8(isolate);
3441 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); 3456 i::Handle<i::JSReceiver> self = Utils::OpenHandle(this);
3442 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key); 3457 i::Handle<i::Object> key_obj = Utils::OpenHandle(*key);
3443 EXCEPTION_PREAMBLE(isolate); 3458 EXCEPTION_PREAMBLE(isolate);
3444 i::Handle<i::Object> obj = i::HasProperty(self, key_obj); 3459 i::Handle<i::Object> obj = i::HasProperty(self, key_obj);
3445 has_pending_exception = obj.is_null(); 3460 has_pending_exception = obj.is_null();
3446 EXCEPTION_BAILOUT_CHECK(isolate, false); 3461 EXCEPTION_BAILOUT_CHECK(isolate, false);
3447 return obj->IsTrue(); 3462 return obj->IsTrue();
3448 } 3463 }
3449 3464
3450 3465
3466 bool v8::Object::HasPrivate(v8::Handle<Private> key) {
3467 return Has(*reinterpret_cast<v8::Handle<Value>*>(&key));
3468 }
3469
3470
3451 bool v8::Object::Delete(uint32_t index) { 3471 bool v8::Object::Delete(uint32_t index) {
3452 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); 3472 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
3453 ON_BAILOUT(isolate, "v8::Object::DeleteProperty()", 3473 ON_BAILOUT(isolate, "v8::Object::DeleteProperty()",
3454 return false); 3474 return false);
3455 ENTER_V8(isolate); 3475 ENTER_V8(isolate);
3456 HandleScope scope(reinterpret_cast<Isolate*>(isolate)); 3476 HandleScope scope(reinterpret_cast<Isolate*>(isolate));
3457 i::Handle<i::JSObject> self = Utils::OpenHandle(this); 3477 i::Handle<i::JSObject> self = Utils::OpenHandle(this);
3458 return i::JSReceiver::DeleteElement(self, index)->IsTrue(); 3478 return i::JSReceiver::DeleteElement(self, index)->IsTrue();
3459 } 3479 }
3460 3480
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after
4856 i::Handle<i::ExternalAsciiString>::cast(str)->resource(); 4876 i::Handle<i::ExternalAsciiString>::cast(str)->resource();
4857 return reinterpret_cast<const ExternalAsciiStringResource*>(resource); 4877 return reinterpret_cast<const ExternalAsciiStringResource*>(resource);
4858 } else { 4878 } else {
4859 return NULL; 4879 return NULL;
4860 } 4880 }
4861 } 4881 }
4862 4882
4863 4883
4864 Local<Value> Symbol::Name() const { 4884 Local<Value> Symbol::Name() const {
4865 i::Handle<i::Symbol> sym = Utils::OpenHandle(this); 4885 i::Handle<i::Symbol> sym = Utils::OpenHandle(this);
4886 ASSERT(!sym->IsPrivate());
4866 i::Handle<i::Object> name(sym->name(), sym->GetIsolate()); 4887 i::Handle<i::Object> name(sym->name(), sym->GetIsolate());
4867 return Utils::ToLocal(name); 4888 return Utils::ToLocal(name);
4868 } 4889 }
4890
4891
4892 Local<Value> Private::Name() const {
4893 i::Handle<i::Private> sym = Utils::OpenHandle(this);
4894 i::Handle<i::Object> name(sym->name(), sym->GetIsolate());
4895 return Utils::ToLocal(name);
4896 }
4869 4897
4870 4898
4871 double Number::Value() const { 4899 double Number::Value() const {
4872 i::Handle<i::Object> obj = Utils::OpenHandle(this); 4900 i::Handle<i::Object> obj = Utils::OpenHandle(this);
4873 return obj->Number(); 4901 return obj->Number();
4874 } 4902 }
4875 4903
4876 4904
4877 bool Boolean::Value() const { 4905 bool Boolean::Value() const {
4878 i::Handle<i::Object> obj = Utils::OpenHandle(this); 4906 i::Handle<i::Object> obj = Utils::OpenHandle(this);
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
6142 ENTER_V8(i_isolate); 6170 ENTER_V8(i_isolate);
6143 if (length == -1) length = i::StrLength(data); 6171 if (length == -1) length = i::StrLength(data);
6144 i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8( 6172 i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8(
6145 i::Vector<const char>(data, length)); 6173 i::Vector<const char>(data, length));
6146 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); 6174 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
6147 result->set_name(*name); 6175 result->set_name(*name);
6148 return Utils::ToLocal(result); 6176 return Utils::ToLocal(result);
6149 } 6177 }
6150 6178
6151 6179
6180 Local<Private> v8::Private::New(Isolate* isolate) {
6181 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6182 EnsureInitializedForIsolate(i_isolate, "v8::Private::New()");
6183 LOG_API(i_isolate, "Private::New()");
6184 ENTER_V8(i_isolate);
6185 i::Handle<i::Private> result = i_isolate->factory()->NewPrivate();
6186 return Utils::ToLocal(result);
6187 }
6188
6189
6190 Local<Private> v8::Private::New(
6191 Isolate* isolate, const char* data, int length) {
6192 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6193 EnsureInitializedForIsolate(i_isolate, "v8::Private::New()");
6194 LOG_API(i_isolate, "Private::New(char)");
6195 ENTER_V8(i_isolate);
6196 if (length == -1) length = i::StrLength(data);
6197 i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8(
6198 i::Vector<const char>(data, length));
6199 i::Handle<i::Private> result = i_isolate->factory()->NewPrivate();
6200 result->set_name(*name);
6201 return Utils::ToLocal(result);
Yang 2013/10/29 12:47:26 I think you could unify those two New functions by
rossberg 2013/10/29 15:08:19 Done (also for the Symbol class).
6202 }
6203
6204
6152 Local<Number> v8::Number::New(double value) { 6205 Local<Number> v8::Number::New(double value) {
6153 i::Isolate* isolate = i::Isolate::Current(); 6206 i::Isolate* isolate = i::Isolate::Current();
6154 EnsureInitializedForIsolate(isolate, "v8::Number::New()"); 6207 EnsureInitializedForIsolate(isolate, "v8::Number::New()");
6155 return Number::New(reinterpret_cast<Isolate*>(isolate), value); 6208 return Number::New(reinterpret_cast<Isolate*>(isolate), value);
6156 } 6209 }
6157 6210
6158 6211
6159 Local<Number> v8::Number::New(Isolate* isolate, double value) { 6212 Local<Number> v8::Number::New(Isolate* isolate, double value) {
6160 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 6213 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6161 ASSERT(internal_isolate->IsInitialized()); 6214 ASSERT(internal_isolate->IsInitialized());
(...skipping 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after
7570 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7623 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7571 Address callback_address = 7624 Address callback_address =
7572 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7625 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7573 VMState<EXTERNAL> state(isolate); 7626 VMState<EXTERNAL> state(isolate);
7574 ExternalCallbackScope call_scope(isolate, callback_address); 7627 ExternalCallbackScope call_scope(isolate, callback_address);
7575 callback(info); 7628 callback(info);
7576 } 7629 }
7577 7630
7578 7631
7579 } } // namespace v8::internal 7632 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/api.h ('k') | src/array-iterator.js » ('j') | src/objects.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698