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

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

Issue 313993002: Bindings: Add ScalarValueString support (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Incorporate review feedback Created 6 years, 6 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) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 return numberObject->NumberValue(); 492 return numberObject->NumberValue();
493 } 493 }
494 494
495 String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState) 495 String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
496 { 496 {
497 // Handle [Default=NullString] 497 // Handle [Default=NullString]
498 if (value.IsEmpty()) 498 if (value.IsEmpty())
499 return String(); 499 return String();
500 500
501 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString 501 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString
502 if (value.IsEmpty())
503 return String();
502 504
503 // 1. Let x be ToString(v) 505 // 1. Let x be ToString(v)
504 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::String>, stringObject, value-> ToString(), exceptionState, String()); 506 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::String>, stringObject, value-> ToString(), exceptionState, String());
505 String x = toCoreString(stringObject); 507 String x = toCoreString(stringObject);
506 508
507 // 2. If the value of any element of x is greater than 255, then throw a Typ eError. 509 // 2. If the value of any element of x is greater than 255, then throw a Typ eError.
508 if (!x.containsOnlyLatin1()) { 510 if (!x.containsOnlyLatin1()) {
509 exceptionState.throwTypeError("Value is not a valid ByteString."); 511 exceptionState.throwTypeError("Value is not a valid ByteString.");
510 return String(); 512 return String();
511 } 513 }
512 514
513 // 3. Return an IDL ByteString value whose length is the length of x, and wh ere the 515 // 3. Return an IDL ByteString value whose length is the length of x, and wh ere the
514 // value of each element is the value of the corresponding element of x. 516 // value of each element is the value of the corresponding element of x.
515 // Blink: A ByteString is simply a String with a range constrained per the a bove, so 517 // Blink: A ByteString is simply a String with a range constrained per the a bove, so
516 // this is the identity operation. 518 // this is the identity operation.
517 return x; 519 return x;
518 } 520 }
519 521
522 String toScalarValueString(v8::Handle<v8::Value> value, ExceptionState& exceptio nState)
523 {
524 // From the Encoding standard (with a TODO to move to Web IDL):
525 // http://encoding.spec.whatwg.org/#type-scalarvaluestring
526 if (value.IsEmpty())
527 return String();
528 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::String>, stringObject, value-> ToString(), exceptionState, String());
529
530 // ScalarValueString is identical to DOMString except that "convert a
531 // DOMString to a sequence of Unicode characters" is used subsequently
532 // when converting to an IDL value
533 String x = toCoreString(stringObject);
534 return x.toScalarValueString();
535 }
536
520 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::Isolate* isolate) 537 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::Isolate* isolate)
521 { 538 {
522 RefPtrWillBeRawPtr<XPathNSResolver> resolver = nullptr; 539 RefPtrWillBeRawPtr<XPathNSResolver> resolver = nullptr;
523 if (V8XPathNSResolver::hasInstance(value, isolate)) 540 if (V8XPathNSResolver::hasInstance(value, isolate))
524 resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(valu e)); 541 resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(valu e));
525 else if (value->IsObject()) 542 else if (value->IsObject())
526 resolver = V8CustomXPathNSResolver::create(value->ToObject(), isolate); 543 resolver = V8CustomXPathNSResolver::create(value->ToObject(), isolate);
527 return resolver; 544 return resolver;
528 } 545 }
529 546
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(Executio nContext* context, v8::Handle<v8::Function> function, v8::Isolate* isolate) 827 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(Executio nContext* context, v8::Handle<v8::Function> function, v8::Isolate* isolate)
811 { 828 {
812 int scriptId = 0; 829 int scriptId = 0;
813 String resourceName; 830 String resourceName;
814 int lineNumber = 1; 831 int lineNumber = 1;
815 GetDevToolsFunctionInfo(function, isolate, scriptId, resourceName, lineNumbe r); 832 GetDevToolsFunctionInfo(function, isolate, scriptId, resourceName, lineNumbe r);
816 return InspectorFunctionCallEvent::data(context, scriptId, resourceName, lin eNumber); 833 return InspectorFunctionCallEvent::data(context, scriptId, resourceName, lin eNumber);
817 } 834 }
818 835
819 } // namespace WebCore 836 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698