Skip to content

Commit

Permalink
Merge pull request #1914 from opal/elia/remove-marshal-binary-string
Browse files Browse the repository at this point in the history
Remove Marshal::BinaryString
  • Loading branch information
elia committed Dec 26, 2018
2 parents 48c2305 + fef7ad3 commit d8edec7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
12 changes: 0 additions & 12 deletions opal/corelib/marshal.rb
Expand Up @@ -5,18 +5,6 @@ module Marshal
MAJOR_VERSION = 4
MINOR_VERSION = 8

# For simulating binary strings
#
class BinaryString < String
def encoding
Encoding::BINARY
end

def +(other)
BinaryString.new(super)
end
end

class << self
def dump(object)
WriteBuffer.new(object).write
Expand Down
14 changes: 11 additions & 3 deletions opal/corelib/marshal/write_buffer.rb
Expand Up @@ -182,9 +182,17 @@ module Marshal
class WriteBuffer
attr_reader :buffer

%x{
function binaryString(s) {
s = new String(s);
s.encoding = #{Encoding::BINARY};
return s;
}
}

def initialize(object)
@object = object
@buffer = BinaryString.new
@buffer = ''
@cache = []
@extends = Hash.new { |h, k| h[k] = [] }
append(version)
Expand Down Expand Up @@ -212,7 +220,7 @@ def write(object = @object)
end
end

@buffer
`binaryString(#{@buffer})`
end

def write_fixnum(n)
Expand Down Expand Up @@ -398,7 +406,7 @@ def write_ivars_prefix(object)
end

def append(s)
@buffer += s
`#{@buffer} += #{s}`
end

def version
Expand Down

0 comments on commit d8edec7

Please sign in to comment.