Skip to content

Commit

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

def available?
Truffle::Interop.supported_mime_types.include?('application/javascript')
Truffle::Interop.mime_type_supported?('application/javascript')
end

end
Original file line number Diff line number Diff line change
@@ -8,14 +8,14 @@

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)
describe "Truffle::Interop.mime_type_supported?" do
it "returns true for application/x-ruby" do
Truffle::Interop.mime_type_supported?('application/x-ruby').should be_true
end

it "includes application/x-ruby" do
Truffle::Interop.supported_mime_types.should include('application/x-ruby')
it "returns false for application/x-this-language-does-not-exist" do
Truffle::Interop.mime_type_supported?('application/x-this-language-does-not-exist').should be_false
end

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

}

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

public SupportedMimeTypesNode(RubyContext context, SourceSection sourceSection) {
public MimeTypeSupportedNode(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);
@Specialization(guards = "isRubyString(mimeType)")
public boolean isMimeTypeSupported(DynamicObject mimeType) {
return getContext().getEnv().isMimeTypeSupported(mimeType.toString());
}

}

0 comments on commit c465d06

Please sign in to comment.