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

Side by Side Diff: src/api.cc

Issue 196103004: Add support for per-isolate private symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: More comments; force dictionary mode Created 6 years, 9 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 | Annotate | Revision Log
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 6118 matching lines...) Expand 10 before | Expand all | Expand 10 after
6129 LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)"); 6129 LOG_API(isolate, "v8::DataView::New(void*, size_t, size_t)");
6130 ENTER_V8(isolate); 6130 ENTER_V8(isolate);
6131 i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView(); 6131 i::Handle<i::JSDataView> obj = isolate->factory()->NewJSDataView();
6132 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer); 6132 i::Handle<i::JSArrayBuffer> buffer = Utils::OpenHandle(*array_buffer);
6133 SetupArrayBufferView( 6133 SetupArrayBufferView(
6134 isolate, obj, buffer, byte_offset, byte_length); 6134 isolate, obj, buffer, byte_offset, byte_length);
6135 return Utils::ToLocal(obj); 6135 return Utils::ToLocal(obj);
6136 } 6136 }
6137 6137
6138 6138
6139 Local<Symbol> v8::Symbol::New(Isolate* isolate, const char* data, int length) { 6139 Local<Symbol> v8::Symbol::New(Isolate* isolate, Local<String> name) {
6140 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6140 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6141 EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()"); 6141 EnsureInitializedForIsolate(i_isolate, "v8::Symbol::New()");
6142 LOG_API(i_isolate, "Symbol::New()"); 6142 LOG_API(i_isolate, "Symbol::New()");
6143 ENTER_V8(i_isolate); 6143 ENTER_V8(i_isolate);
6144 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol(); 6144 i::Handle<i::Symbol> result = i_isolate->factory()->NewSymbol();
6145 if (data != NULL) { 6145 if (!name.IsEmpty()) result->set_name(*Utils::OpenHandle(*name));
6146 if (length == -1) length = i::StrLength(data);
6147 i::Handle<i::String> name = i_isolate->factory()->NewStringFromUtf8(
6148 i::Vector<const char>(data, length));
6149 result->set_name(*name);
6150 }
6151 return Utils::ToLocal(result); 6146 return Utils::ToLocal(result);
6152 } 6147 }
6153 6148
6154 6149
6155 Local<Private> v8::Private::New( 6150 Local<Symbol> v8::Symbol::For(Isolate* isolate, Local<String> name) {
6156 Isolate* isolate, Local<String> name) { 6151 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6152 i::Handle<i::String> i_name = Utils::OpenHandle(*name);
6153 i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry();
6154 i::Handle<i::String> part = i_isolate->factory()->for_string();
6155 i::Handle<i::JSObject> symbols =
6156 i::Handle<i::JSObject>::cast(i::JSObject::GetProperty(registry, part));
6157 i::Handle<i::Object> symbol = i::JSObject::GetProperty(symbols, i_name);
6158 if (!symbol->IsSymbol()) {
6159 ASSERT(symbol->IsUndefined());
6160 symbol = i_isolate->factory()->NewSymbol();
6161 i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
6162 i::JSObject::SetProperty(symbols, i_name, symbol, NONE, i::STRICT);
6163 }
6164 return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
6165 }
6166
6167
6168 Local<Symbol> v8::Symbol::ForApi(Isolate* isolate, Local<String> name) {
6169 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6170 i::Handle<i::String> i_name = Utils::OpenHandle(*name);
6171 i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry();
6172 i::Handle<i::String> part = i_isolate->factory()->for_api_string();
6173 i::Handle<i::JSObject> symbols =
6174 i::Handle<i::JSObject>::cast(i::JSObject::GetProperty(registry, part));
6175 i::Handle<i::Object> symbol = i::JSObject::GetProperty(symbols, i_name);
6176 if (!symbol->IsSymbol()) {
6177 ASSERT(symbol->IsUndefined());
6178 symbol = i_isolate->factory()->NewSymbol();
6179 i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
6180 i::JSObject::SetProperty(symbols, i_name, symbol, NONE, i::STRICT);
6181 }
6182 return Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
6183 }
6184
6185
6186 Local<Private> v8::Private::New(Isolate* isolate, Local<String> name) {
6157 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 6187 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6158 EnsureInitializedForIsolate(i_isolate, "v8::Private::New()"); 6188 EnsureInitializedForIsolate(i_isolate, "v8::Private::New()");
6159 LOG_API(i_isolate, "Private::New()"); 6189 LOG_API(i_isolate, "Private::New()");
6160 ENTER_V8(i_isolate); 6190 ENTER_V8(i_isolate);
6161 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol(); 6191 i::Handle<i::Symbol> symbol = i_isolate->factory()->NewPrivateSymbol();
6162 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name)); 6192 if (!name.IsEmpty()) symbol->set_name(*Utils::OpenHandle(*name));
6163 Local<Symbol> result = Utils::ToLocal(symbol); 6193 Local<Symbol> result = Utils::ToLocal(symbol);
6164 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); 6194 return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
6165 } 6195 }
6166 6196
6167 6197
6198 Local<Private> v8::Private::ForApi(Isolate* isolate, Local<String> name) {
6199 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
6200 i::Handle<i::String> i_name = Utils::OpenHandle(*name);
6201 i::Handle<i::JSObject> registry = i_isolate->GetSymbolRegistry();
6202 i::Handle<i::String> part = i_isolate->factory()->private_api_string();
6203 i::Handle<i::JSObject> privates =
6204 i::Handle<i::JSObject>::cast(i::JSObject::GetProperty(registry, part));
6205 i::Handle<i::Object> symbol = i::JSObject::GetProperty(privates, i_name);
6206 if (!symbol->IsSymbol()) {
6207 ASSERT(symbol->IsUndefined());
6208 symbol = i_isolate->factory()->NewPrivateSymbol();
6209 i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
6210 i::JSObject::SetProperty(privates, i_name, symbol, NONE, i::STRICT);
6211 }
6212 Local<Symbol> result = Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
6213 return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
6214 }
6215
6216
6168 Local<Number> v8::Number::New(Isolate* isolate, double value) { 6217 Local<Number> v8::Number::New(Isolate* isolate, double value) {
6169 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 6218 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6170 ASSERT(internal_isolate->IsInitialized()); 6219 ASSERT(internal_isolate->IsInitialized());
6171 if (std::isnan(value)) { 6220 if (std::isnan(value)) {
6172 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. 6221 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
6173 value = i::OS::nan_value(); 6222 value = i::OS::nan_value();
6174 } 6223 }
6175 ENTER_V8(internal_isolate); 6224 ENTER_V8(internal_isolate);
6176 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); 6225 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
6177 return Utils::NumberToLocal(result); 6226 return Utils::NumberToLocal(result);
(...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after
7597 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7646 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7598 Address callback_address = 7647 Address callback_address =
7599 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7648 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7600 VMState<EXTERNAL> state(isolate); 7649 VMState<EXTERNAL> state(isolate);
7601 ExternalCallbackScope call_scope(isolate, callback_address); 7650 ExternalCallbackScope call_scope(isolate, callback_address);
7602 callback(info); 7651 callback(info);
7603 } 7652 }
7604 7653
7605 7654
7606 } } // namespace v8::internal 7655 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/array-iterator.js » ('j') | src/isolate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698