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

Side by Side Diff: Source/bindings/v8/V8Binding.h

Issue 116983005: Use v8AtomicString instead of v8::String::NewFromUtf8 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 11 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 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * Copyright (C) 2012 Ericsson AB. All rights reserved. 3 * Copyright (C) 2012 Ericsson AB. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // Return a V8 external string that shares the underlying buffer with the gi ven 195 // Return a V8 external string that shares the underlying buffer with the gi ven
196 // WebCore string. The reference counting mechanism is used to keep the 196 // WebCore string. The reference counting mechanism is used to keep the
197 // underlying buffer alive while the string is still live in the V8 engine. 197 // underlying buffer alive while the string is still live in the V8 engine.
198 inline v8::Handle<v8::String> v8String(v8::Isolate* isolate, const String& s tring) 198 inline v8::Handle<v8::String> v8String(v8::Isolate* isolate, const String& s tring)
199 { 199 {
200 if (string.isNull()) 200 if (string.isNull())
201 return v8::String::Empty(isolate); 201 return v8::String::Empty(isolate);
202 return V8PerIsolateData::from(isolate)->stringCache()->v8ExternalString( string.impl(), isolate); 202 return V8PerIsolateData::from(isolate)->stringCache()->v8ExternalString( string.impl(), isolate);
203 } 203 }
204 204
205 inline v8::Handle<v8::String> v8AtomicString(v8::Isolate* isolate, const cha r* str)
206 {
207 ASSERT(isolate);
208 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedSt ring, strlen(str));
209 }
210
211 inline v8::Handle<v8::String> v8AtomicString(v8::Isolate* isolate, const cha r* str, size_t length)
212 {
213 ASSERT(isolate);
214 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedSt ring, length);
215 }
216
205 inline v8::Handle<v8::Value> v8Undefined() 217 inline v8::Handle<v8::Value> v8Undefined()
206 { 218 {
207 return v8::Handle<v8::Value>(); 219 return v8::Handle<v8::Value>();
208 } 220 }
209 221
210 template <class T> 222 template <class T>
211 struct V8ValueTraits { 223 struct V8ValueTraits {
212 static inline v8::Handle<v8::Value> arrayV8Value(const T& value, v8::Iso late* isolate) 224 static inline v8::Handle<v8::Value> arrayV8Value(const T& value, v8::Iso late* isolate)
213 { 225 {
214 return toV8(WTF::getPtr(value), v8::Handle<v8::Object>(), isolate); 226 return toV8(WTF::getPtr(value), v8::Handle<v8::Object>(), isolate);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 ASSERT(!value->IsArray()); 546 ASSERT(!value->IsArray());
535 // FIXME: Do we really need to special case Date and RegExp object? 547 // FIXME: Do we really need to special case Date and RegExp object?
536 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806 548 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=22806
537 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) { 549 if (!value->IsObject() || value->IsDate() || value->IsRegExp()) {
538 // The caller is responsible for reporting a TypeError. 550 // The caller is responsible for reporting a TypeError.
539 return v8Undefined(); 551 return v8Undefined();
540 } 552 }
541 553
542 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value)); 554 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(isolate, value));
543 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value); 555 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(v8Value);
544 v8::Local<v8::String> lengthSymbol = v8::String::NewFromUtf8(isolate, "l ength", v8::String::kInternalizedString, 6); 556 v8::Local<v8::String> lengthSymbol = v8AtomicString(isolate, "length");
545 557
546 // FIXME: The specification states that the length property should be us ed as fallback, if value 558 // FIXME: The specification states that the length property should be us ed as fallback, if value
547 // is not a platform object that supports indexed properties. If it supp orts indexed properties, 559 // is not a platform object that supports indexed properties. If it supp orts indexed properties,
548 // length should actually be one greater than value’s maximum indexed pr operty index. 560 // length should actually be one greater than value’s maximum indexed pr operty index.
549 V8TRYCATCH(v8::Local<v8::Value>, lengthValue, object->Get(lengthSymbol)) ; 561 V8TRYCATCH(v8::Local<v8::Value>, lengthValue, object->Get(lengthSymbol)) ;
550 562
551 if (lengthValue->IsUndefined() || lengthValue->IsNull()) { 563 if (lengthValue->IsUndefined() || lengthValue->IsNull()) {
552 // The caller is responsible for reporting a TypeError. 564 // The caller is responsible for reporting a TypeError.
553 return v8Undefined(); 565 return v8Undefined();
554 } 566 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 return object->NumberValue(); 611 return object->NumberValue();
600 return std::numeric_limits<double>::quiet_NaN(); 612 return std::numeric_limits<double>::quiet_NaN();
601 } 613 }
602 614
603 inline v8::Handle<v8::Value> v8DateOrNull(double value, v8::Isolate* isolate ) 615 inline v8::Handle<v8::Value> v8DateOrNull(double value, v8::Isolate* isolate )
604 { 616 {
605 ASSERT(isolate); 617 ASSERT(isolate);
606 return std::isfinite(value) ? v8::Date::New(isolate, value) : v8::Handle <v8::Value>::Cast(v8::Null(isolate)); 618 return std::isfinite(value) ? v8::Date::New(isolate, value) : v8::Handle <v8::Value>::Cast(v8::Null(isolate));
607 } 619 }
608 620
609 inline v8::Handle<v8::String> v8AtomicString(v8::Isolate* isolate, const cha r* str)
610 {
611 ASSERT(isolate);
612 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedSt ring, strlen(str));
613 }
614
615 inline v8::Handle<v8::String> v8AtomicString(v8::Isolate* isolate, const cha r* str, size_t length)
616 {
617 ASSERT(isolate);
618 return v8::String::NewFromUtf8(isolate, str, v8::String::kInternalizedSt ring, length);
619 }
620
621
622 v8::Handle<v8::FunctionTemplate> createRawTemplate(v8::Isolate*); 621 v8::Handle<v8::FunctionTemplate> createRawTemplate(v8::Isolate*);
623 622
624 PassRefPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value>, v8::Iso late*); 623 PassRefPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value>, v8::Iso late*);
625 624
626 v8::Handle<v8::Object> toInnerGlobalObject(v8::Handle<v8::Context>); 625 v8::Handle<v8::Object> toInnerGlobalObject(v8::Handle<v8::Context>);
627 DOMWindow* toDOMWindow(v8::Handle<v8::Context>); 626 DOMWindow* toDOMWindow(v8::Handle<v8::Context>);
628 ExecutionContext* toExecutionContext(v8::Handle<v8::Context>); 627 ExecutionContext* toExecutionContext(v8::Handle<v8::Context>);
629 628
630 DOMWindow* activeDOMWindow(); 629 DOMWindow* activeDOMWindow();
631 ExecutionContext* activeExecutionContext(); 630 ExecutionContext* activeExecutionContext();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 // Result values for platform object 'deleter' methods, 699 // Result values for platform object 'deleter' methods,
701 // http://www.w3.org/TR/WebIDL/#delete 700 // http://www.w3.org/TR/WebIDL/#delete
702 enum DeleteResult { 701 enum DeleteResult {
703 DeleteSuccess, 702 DeleteSuccess,
704 DeleteReject, 703 DeleteReject,
705 DeleteUnknownProperty 704 DeleteUnknownProperty
706 }; 705 };
707 } // namespace WebCore 706 } // namespace WebCore
708 707
709 #endif // V8Binding_h 708 #endif // V8Binding_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698