Skip to content

Commit

Permalink
Showing 3 changed files with 46 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/ruby/truffle/truffle/truffle/execjs.rb
Original file line number Diff line number Diff line change
@@ -65,9 +65,7 @@ def name
end

def available?
defined?(Truffle::Interop) && Truffle::Interop.eval(JS_MIME_TYPE, 'true')
rescue RubyTruffleError
false
Truffle::Interop.supported_mime_types.include?('application/javascript')
end

end
21 changes: 21 additions & 0 deletions spec/truffle/specs/truffle/interop/supported_mime_types_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.supported_mime_types" do

it "returns an Array" do
Truffle::Interop.supported_mime_types.should be_kind_of(Array)
end

it "includes application/x-ruby" do
Truffle::Interop.supported_mime_types.should include('application/x-ruby')
end

end
Original file line number Diff line number Diff line change
@@ -426,6 +426,30 @@ public Object importObject(DynamicObject name) {

}

@CoreMethod(names = "supported_mime_types", isModuleFunction = true, needsSelf = false)
public abstract static class SupportedMimeTypesNode extends CoreMethodArrayArgumentsNode {

public SupportedMimeTypesNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization
public DynamicObject supportedMimeTypes() {
final String[] supportedMimeTypes = getContext().getEnv().getSupportedMimeTypes();
final Object[] supportedMimeTypesTruffle = new Object[supportedMimeTypes.length];

for (int n = 0; n < supportedMimeTypes.length; n++) {
supportedMimeTypesTruffle[n] = Layouts.STRING.createString(
getContext().getCoreLibrary().getStringFactory(),
ByteList.create(supportedMimeTypes[n]), StringSupport.CR_UNKNOWN, null);
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), supportedMimeTypesTruffle, supportedMimeTypesTruffle.length);
}

}

@CoreMethod(names = "eval", isModuleFunction = true, needsSelf = false, required = 2)
@ImportStatic(StringCachingGuards.class)
public abstract static class EvalNode extends CoreMethodArrayArgumentsNode {

0 comments on commit 0a53b78

Please sign in to comment.