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

Side by Side Diff: samples/process.cc

Issue 467013003: Add interceptor support for symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Updated to filter out non-symbol keys from for-in enumeration Created 6 years, 3 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
« no previous file with comments | « include/v8.h ('k') | src/api.cc » ('j') | 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 static void GetPath(Local<String> name, 109 static void GetPath(Local<String> name,
110 const PropertyCallbackInfo<Value>& info); 110 const PropertyCallbackInfo<Value>& info);
111 static void GetReferrer(Local<String> name, 111 static void GetReferrer(Local<String> name,
112 const PropertyCallbackInfo<Value>& info); 112 const PropertyCallbackInfo<Value>& info);
113 static void GetHost(Local<String> name, 113 static void GetHost(Local<String> name,
114 const PropertyCallbackInfo<Value>& info); 114 const PropertyCallbackInfo<Value>& info);
115 static void GetUserAgent(Local<String> name, 115 static void GetUserAgent(Local<String> name,
116 const PropertyCallbackInfo<Value>& info); 116 const PropertyCallbackInfo<Value>& info);
117 117
118 // Callbacks that access maps 118 // Callbacks that access maps
119 static void MapGet(Local<String> name, 119 static void MapGet(Local<Name> name,
120 const PropertyCallbackInfo<Value>& info); 120 const PropertyCallbackInfo<Value>& info);
121 static void MapSet(Local<String> name, 121 static void MapSet(Local<Name> name,
122 Local<Value> value, 122 Local<Value> value,
123 const PropertyCallbackInfo<Value>& info); 123 const PropertyCallbackInfo<Value>& info);
124 124
125 // Utility methods for wrapping C++ objects as JavaScript objects, 125 // Utility methods for wrapping C++ objects as JavaScript objects,
126 // and going back again. 126 // and going back again.
127 Handle<Object> WrapMap(map<string, string>* obj); 127 Handle<Object> WrapMap(map<string, string>* obj);
128 static map<string, string>* UnwrapMap(Handle<Object> obj); 128 static map<string, string>* UnwrapMap(Handle<Object> obj);
129 Handle<Object> WrapRequest(HttpRequest* obj); 129 Handle<Object> WrapRequest(HttpRequest* obj);
130 static HttpRequest* UnwrapRequest(Handle<Object> obj); 130 static HttpRequest* UnwrapRequest(Handle<Object> obj);
131 131
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 352
353 353
354 // Convert a JavaScript string to a std::string. To not bother too 354 // Convert a JavaScript string to a std::string. To not bother too
355 // much with string encodings we just use ascii. 355 // much with string encodings we just use ascii.
356 string ObjectToString(Local<Value> value) { 356 string ObjectToString(Local<Value> value) {
357 String::Utf8Value utf8_value(value); 357 String::Utf8Value utf8_value(value);
358 return string(*utf8_value); 358 return string(*utf8_value);
359 } 359 }
360 360
361 361
362 void JsHttpRequestProcessor::MapGet(Local<String> name, 362 void JsHttpRequestProcessor::MapGet(Local<Name> name,
363 const PropertyCallbackInfo<Value>& info) { 363 const PropertyCallbackInfo<Value>& info) {
364 if (name->IsSymbol()) return;
365
364 // Fetch the map wrapped by this object. 366 // Fetch the map wrapped by this object.
365 map<string, string>* obj = UnwrapMap(info.Holder()); 367 map<string, string>* obj = UnwrapMap(info.Holder());
366 368
367 // Convert the JavaScript string to a std::string. 369 // Convert the JavaScript string to a std::string.
368 string key = ObjectToString(name); 370 string key = ObjectToString(Local<String>::Cast(name));
369 371
370 // Look up the value if it exists using the standard STL ideom. 372 // Look up the value if it exists using the standard STL ideom.
371 map<string, string>::iterator iter = obj->find(key); 373 map<string, string>::iterator iter = obj->find(key);
372 374
373 // If the key is not present return an empty handle as signal 375 // If the key is not present return an empty handle as signal
374 if (iter == obj->end()) return; 376 if (iter == obj->end()) return;
375 377
376 // Otherwise fetch the value and wrap it in a JavaScript string 378 // Otherwise fetch the value and wrap it in a JavaScript string
377 const string& value = (*iter).second; 379 const string& value = (*iter).second;
378 info.GetReturnValue().Set(String::NewFromUtf8( 380 info.GetReturnValue().Set(String::NewFromUtf8(
379 info.GetIsolate(), value.c_str(), String::kNormalString, 381 info.GetIsolate(), value.c_str(), String::kNormalString,
380 static_cast<int>(value.length()))); 382 static_cast<int>(value.length())));
381 } 383 }
382 384
383 385
384 void JsHttpRequestProcessor::MapSet(Local<String> name, 386 void JsHttpRequestProcessor::MapSet(Local<Name> name,
385 Local<Value> value_obj, 387 Local<Value> value_obj,
386 const PropertyCallbackInfo<Value>& info) { 388 const PropertyCallbackInfo<Value>& info) {
389 if (name->IsSymbol()) return;
390
387 // Fetch the map wrapped by this object. 391 // Fetch the map wrapped by this object.
388 map<string, string>* obj = UnwrapMap(info.Holder()); 392 map<string, string>* obj = UnwrapMap(info.Holder());
389 393
390 // Convert the key and value to std::strings. 394 // Convert the key and value to std::strings.
391 string key = ObjectToString(name); 395 string key = ObjectToString(Local<String>::Cast(name));
392 string value = ObjectToString(value_obj); 396 string value = ObjectToString(value_obj);
393 397
394 // Update the map. 398 // Update the map.
395 (*obj)[key] = value; 399 (*obj)[key] = value;
396 400
397 // Return the value; any non-empty handle will work. 401 // Return the value; any non-empty handle will work.
398 info.GetReturnValue().Set(value_obj); 402 info.GetReturnValue().Set(value_obj);
399 } 403 }
400 404
401 405
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 JsHttpRequestProcessor processor(isolate, source); 670 JsHttpRequestProcessor processor(isolate, source);
667 map<string, string> output; 671 map<string, string> output;
668 if (!processor.Initialize(&options, &output)) { 672 if (!processor.Initialize(&options, &output)) {
669 fprintf(stderr, "Error initializing processor.\n"); 673 fprintf(stderr, "Error initializing processor.\n");
670 return 1; 674 return 1;
671 } 675 }
672 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests)) 676 if (!ProcessEntries(&processor, kSampleSize, kSampleRequests))
673 return 1; 677 return 1;
674 PrintMap(&output); 678 PrintMap(&output);
675 } 679 }
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698