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

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

Issue 309553002: Add ByteString support to IDL bindings (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add [Default=NullString] support 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
« no previous file with comments | « Source/bindings/v8/V8Binding.h ('k') | Source/bindings/v8/V8StringResource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 NonThrowableExceptionState exceptionState; 485 NonThrowableExceptionState exceptionState;
486 return toUInt64(value, NormalConversion, exceptionState); 486 return toUInt64(value, NormalConversion, exceptionState);
487 } 487 }
488 488
489 float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState) 489 float toFloat(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
490 { 490 {
491 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0); 491 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::Number>, numberObject, value-> ToNumber(), exceptionState, 0);
492 return numberObject->NumberValue(); 492 return numberObject->NumberValue();
493 } 493 }
494 494
495 String toByteString(v8::Handle<v8::Value> value, ExceptionState& exceptionState)
496 {
497 // Handle [Default=NullString]
498 if (value.IsEmpty())
499 return String();
500
501 // From the Web IDL spec: http://heycam.github.io/webidl/#es-ByteString
502
503 // 1. Let x be ToString(v)
504 TONATIVE_DEFAULT_EXCEPTIONSTATE(v8::Local<v8::String>, stringObject, value-> ToString(), exceptionState, String());
505 String x = toCoreString(stringObject);
haraken 2014/06/11 03:54:52 I'm not quite sure, but probably this should be:
Nils Barth (inactive) 2014/06/11 03:59:47 Oh, that's a good point, I think. We're only throw
jsbell 2014/06/11 16:55:06 Just to make sure I'm understanding things - TOSTR
jsbell 2014/06/11 16:57:43 And to be clear, the TONATIVE_DEFAULT_EXCEPTIONSTA
haraken 2014/06/11 23:55:16 You're right. Your programming pattern matches wha
506
507 // 2. If the value of any element of x is greater than 255, then throw a Typ eError.
508 if (!x.containsOnlyLatin1()) {
509 exceptionState.throwTypeError("Value is not a valid ByteString.");
510 return String();
511 }
512
513 // 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.
515 // Blink: A ByteString is simply a String with a range constrained per the a bove, so
516 // this is the identity operation.
517 return x;
518 }
519
495 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::Isolate* isolate) 520 PassRefPtrWillBeRawPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value> value, v8::Isolate* isolate)
496 { 521 {
497 RefPtrWillBeRawPtr<XPathNSResolver> resolver = nullptr; 522 RefPtrWillBeRawPtr<XPathNSResolver> resolver = nullptr;
498 if (V8XPathNSResolver::hasInstance(value, isolate)) 523 if (V8XPathNSResolver::hasInstance(value, isolate))
499 resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(valu e)); 524 resolver = V8XPathNSResolver::toNative(v8::Handle<v8::Object>::Cast(valu e));
500 else if (value->IsObject()) 525 else if (value->IsObject())
501 resolver = V8CustomXPathNSResolver::create(value->ToObject(), isolate); 526 resolver = V8CustomXPathNSResolver::create(value->ToObject(), isolate);
502 return resolver; 527 return resolver;
503 } 528 }
504 529
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(Executio nContext* context, v8::Handle<v8::Function> function, v8::Isolate* isolate) 810 PassRefPtr<TraceEvent::ConvertableToTraceFormat> devToolsTraceEventData(Executio nContext* context, v8::Handle<v8::Function> function, v8::Isolate* isolate)
786 { 811 {
787 int scriptId = 0; 812 int scriptId = 0;
788 String resourceName; 813 String resourceName;
789 int lineNumber = 1; 814 int lineNumber = 1;
790 GetDevToolsFunctionInfo(function, isolate, scriptId, resourceName, lineNumbe r); 815 GetDevToolsFunctionInfo(function, isolate, scriptId, resourceName, lineNumbe r);
791 return InspectorFunctionCallEvent::data(context, scriptId, resourceName, lin eNumber); 816 return InspectorFunctionCallEvent::data(context, scriptId, resourceName, lin eNumber);
792 } 817 }
793 818
794 } // namespace WebCore 819 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8Binding.h ('k') | Source/bindings/v8/V8StringResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698