From 4da71d84ebdec9e10f81322776eaeb64d37c0960 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 11 Sep 2014 16:31:33 -0700 Subject: [PATCH] Implement getBoolean native --- .../com/nokia/mid/s40/codec/DataDecoder.java | 4 +--- midp/codec.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/java/custom/com/nokia/mid/s40/codec/DataDecoder.java b/java/custom/com/nokia/mid/s40/codec/DataDecoder.java index 6ad50ba6..0a275c44 100644 --- a/java/custom/com/nokia/mid/s40/codec/DataDecoder.java +++ b/java/custom/com/nokia/mid/s40/codec/DataDecoder.java @@ -29,9 +29,7 @@ public class DataDecoder { throw new RuntimeException("DataDecoder::getName(int) not implemented"); } - public boolean getBoolean() throws IOException { - throw new RuntimeException("DataDecoder::getBoolean() not implemented"); - } + public native boolean getBoolean() throws IOException; public byte[] getByteArray() throws IOException { throw new RuntimeException("DataDecoder::getByteArray() not implemented"); diff --git a/midp/codec.js b/midp/codec.js index c7732dbb..d0389622 100644 --- a/midp/codec.js +++ b/midp/codec.js @@ -74,6 +74,11 @@ DataDecoder.prototype.getValue = function(tag) { return this.find(tag); } +DataDecoder.prototype.getNextValue = function() { + var elem = this.data.shift(); + return (elem) ? elem.value : undefined; +} + DataDecoder.prototype.getName = function() { return this.data[0].name; } @@ -103,7 +108,7 @@ Native["com/nokia/mid/s40/codec/DataEncoder.put.(ILjava/lang/String;J)V"] = func } Native["com/nokia/mid/s40/codec/DataEncoder.put.(ILjava/lang/String;Z)V"] = function(ctx, stack) { - var value = stack.pop(), name = stack.pop(), tag = stack.pop(), _this = stack.pop(); + var value = stack.pop(), name = util.fromJavaString(stack.pop()), tag = stack.pop(), _this = stack.pop(); _this.encoder.put(tag, name, value); } @@ -148,7 +153,6 @@ Native["com/nokia/mid/s40/codec/DataDecoder.getString.(I)Ljava/lang/String;"] = stack.push(ctx.newString(str)); } -// Throw IOException if not found Native["com/nokia/mid/s40/codec/DataDecoder.getInteger.(I)J"] = function(ctx, stack) { var tag = stack.pop(), _this = stack.pop(); var num = _this.decoder.getValue(tag); @@ -158,6 +162,15 @@ Native["com/nokia/mid/s40/codec/DataDecoder.getInteger.(I)J"] = function(ctx, st stack.push2(Long.fromNumber(num)); } +Native["com/nokia/mid/s40/codec/DataDecoder.getBoolean.()Z"] = function(ctx, stack) { + var _this = stack.pop(); + var val = _this.decoder.getNextValue(); + if (val === undefined) { + ctx.raiseExceptionAndYield("java/io/IOException"); + } + stack.push(val); +} + Native["com/nokia/mid/s40/codec/DataDecoder.getName.()Ljava/lang/String;"] = function(ctx, stack) { var _this = stack.pop(); var name = _this.decoder.getName();