OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 5204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5215 LocalContext context; | 5215 LocalContext context; |
5216 Local<ObjectTemplate> templ = ObjectTemplate::New(); | 5216 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
5217 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, | 5217 templ->SetAccessCheckCallbacks(NamedSetAccessBlocker, |
5218 IndexedSetAccessBlocker); | 5218 IndexedSetAccessBlocker); |
5219 templ->Set(v8_str("x"), v8::True()); | 5219 templ->Set(v8_str("x"), v8::True()); |
5220 Local<v8::Object> instance = templ->NewInstance(); | 5220 Local<v8::Object> instance = templ->NewInstance(); |
5221 context->Global()->Set(v8_str("obj"), instance); | 5221 context->Global()->Set(v8_str("obj"), instance); |
5222 Local<Value> value = CompileRun("obj.x"); | 5222 Local<Value> value = CompileRun("obj.x"); |
5223 CHECK(value->BooleanValue()); | 5223 CHECK(value->BooleanValue()); |
5224 } | 5224 } |
| 5225 |
| 5226 |
| 5227 static String::ExternalStringResource* SymbolCallback(const char* chars, |
| 5228 size_t length) { |
| 5229 uint16_t* buffer = i::NewArray<uint16_t>(length + 1); |
| 5230 for (size_t i = 0; i < length; i++) { |
| 5231 buffer[i] = chars[i]; |
| 5232 } |
| 5233 buffer[length] = '\0'; |
| 5234 return new TestResource(buffer); |
| 5235 } |
| 5236 |
| 5237 |
| 5238 static v8::Handle<Value> ExternalSymbolGetter(Local<String> name, |
| 5239 const AccessorInfo& info) { |
| 5240 CHECK(name->IsExternal()); |
| 5241 return v8::True(); |
| 5242 } |
| 5243 |
| 5244 |
| 5245 static void ExternalSymbolSetter(Local<String> name, |
| 5246 Local<Value> value, |
| 5247 const AccessorInfo&) { |
| 5248 CHECK(name->IsExternal()); |
| 5249 } |
| 5250 |
| 5251 |
| 5252 THREADED_TEST(ExternalSymbols) { |
| 5253 TestResource::dispose_count = 0; |
| 5254 v8::V8::SetExternalSymbolCallback(SymbolCallback); |
| 5255 v8::HandleScope scope; |
| 5256 LocalContext context; |
| 5257 Local<ObjectTemplate> templ = ObjectTemplate::New(); |
| 5258 templ->SetAccessor(v8_str("x"), ExternalSymbolGetter, ExternalSymbolSetter); |
| 5259 context->Global()->Set(v8_str("obj"), templ->NewInstance()); |
| 5260 Local<Value> value = CompileRun("var o = { x: 42 }; o.x"); |
| 5261 CHECK_EQ(42, value->Int32Value()); |
| 5262 value = CompileRun("obj.x"); |
| 5263 CHECK_EQ(true, value->BooleanValue()); |
| 5264 value = CompileRun("obj.x = 42"); |
| 5265 v8::V8::SetExternalSymbolCallback(NULL); |
| 5266 } |
OLD | NEW |