Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TextDecoder #5058

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Fixed some issues

  • Loading branch information
KiChjang committed Feb 25, 2015
commit 2d952e432015207ba7c59520e1c80b8a5c2b4284
@@ -26,24 +26,22 @@ use std::borrow::ToOwned;
pub struct TextDecoder {
reflector_: Reflector,
encoding: EncodingRef,
fatal: bool,
ignoreBOM: bool
fatal: bool
}

no_jsmanaged_fields!(EncodingRef);

impl TextDecoder {
fn new_inherited(encoding: EncodingRef, fatal: bool, ignoreBOM: bool) -> TextDecoder {
fn new_inherited(encoding: EncodingRef, fatal: bool) -> TextDecoder {
TextDecoder {
reflector_: Reflector::new(),
encoding: encoding,
fatal: fatal,
ignoreBOM: ignoreBOM
fatal: fatal
}
}

pub fn new(global: GlobalRef, encoding: EncodingRef, fatal: bool, ignoreBOM: bool) -> Temporary<TextDecoder> {
reflect_dom_object(box TextDecoder::new_inherited(encoding, fatal, ignoreBOM),
pub fn new(global: GlobalRef, encoding: EncodingRef, fatal: bool) -> Temporary<TextDecoder> {
reflect_dom_object(box TextDecoder::new_inherited(encoding, fatal),
global,
TextDecoderBinding::Wrap)
}
@@ -57,18 +55,15 @@ impl TextDecoder {
Some(enc) => enc,
None => return Err(Syntax) // FIXME: Should throw a RangeError as per spec
};
Ok(TextDecoder::new(global, encoding, options.fatal, options.ignoreBOM))
Ok(TextDecoder::new(global, encoding, options.fatal))
}
}

impl<'a> TextDecoderMethods for JSRef<'a, TextDecoder> {
pub fn Decode(self,
cx: *mut JSContext,
input: *mut JSObject,
options: &TextDecoderBinding::TextDecodeOptions) -> DOMString {
pub fn Decode(self, cx: *mut JSContext, input: *mut JSObject) -> DOMString {
let stream: *const uint8_t = JS_GetUint8ArrayData(input, cx) as *const uint8_t;
let trap = if self.fatal { DecoderTrap::Strict } else { DecoderTrap::Replace };
unsafe { self.encoding.decode(stream as &[u8], trap).unwrap() };
unsafe { self.encoding.decode(stream as &[u8], trap).unwrap() }
}

fn Encoding(self) -> DOMString {
@@ -80,6 +75,6 @@ impl<'a> TextDecoderMethods for JSRef<'a, TextDecoder> {
}

fn IgnoreBOM(self) -> bool {
self.ignoreBOM
false
}
}
@@ -1,20 +1,20 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* The origin of this file is https://encoding.spec.whatwg.org/#interface-textdecoder
*
*/

dictionary TextDecoderOptions {
boolean fatal = false;
boolean ignoreBOM = false;
// boolean ignoreBOM = false;
};

dictionary TextDecodeOptions {
/*dictionary TextDecodeOptions {
boolean stream = false;
};
};*/

[Constructor(optional DOMString label = "utf-8", optional TextDecoderOptions options)/*,
Exposed=Window,Worker*/]
@@ -23,5 +23,6 @@ interface TextDecoder {
readonly attribute boolean fatal;
readonly attribute boolean ignoreBOM;
// FIXME: decode should return a USVString instead, and ArrayBuffer should really be BufferSource
[Throws]
DOMString decode(optional ArrayBuffer input, optional TextDecodeOptions options);
};
@@ -65,8 +65,8 @@ skip: true
skip: false
[system-state-and-capabilities]
skip: true
[encoding]
skip: false
[encoding]
skip: false
[workers]
skip: false
[constructors]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.