67c42da42935019c9dbab5d35f7da777d2561021
Re: Small usage simplification for Rhino
Date:
Mon, 22 Jan 2001 20:32:12 +0100
From:
Igor Bukanov <igor@icesoft.no>
To:
Norris Boyd <nboyd@atg.com>
References:
1 , 2
Norris Boyd wrote:
> Sounds like a good change to reduce codesize. I'll take the patches for the
> changes.
>
> Thanks,
> Norris
I made this patch, the files in the attachment were produced via:
diff -bB javascript.orig javascript -c > patch_context
and
diff -bB javascript.orig javascript > patch_std
run from org/mozilla directory.
This patch reduces uncopressed Rhino jar by 3K.
>
> Igor Bukanov wrote:
>
>
>> Hi, Noris!
>>
>> To shorten/cleanup usage of getMessage and reportRuntimeError methods
>> from org/mozilla/javascript/Context.java I suggest to add few utility
>> methods like
>>
>> static String getMessage0(String messageId) {
>> return getMessage(messageId, null);
>> }
>>
>> static String getMessage1(String messageId, Object arg1) {
>> Object[] arguments = {arg1};
>> return getMessage(messageId, arguments);
>> }
>>
>> static String getMessage2(String messageId, Object arg1, Object arg2) {
>> Object[] arguments = {arg1, arg2};
>> return getMessage(messageId, arguments);
>> }
>>
>> static String getMessage3
>> (String messageId, Object arg1, Object arg2, Object arg3) {
>> Object[] arguments = {arg1, arg2, arg3};
>> return getMessage(messageId, arguments);
>> }
>>
>> and
>>
>> static EvaluatorException reportRuntimeError0(String messageId) {
>> return reportRuntimeError(getMessage0(messageId));
>> }
>>
>> static EvaluatorException reportRuntimeError1
>> (String messageId, Object arg1)
>> {
>> return reportRuntimeError(getMessage1(messageId, arg1));
>> }
>>
>> static EvaluatorException reportRuntimeError2
>> (String messageId, Object arg1, Object arg2)
>> {
>> return reportRuntimeError(getMessage2(messageId, arg1, arg2));
>> }
>>
>> static EvaluatorException reportRuntimeError3
>> (String messageId, Object arg1, Object arg2, Object arg3)
>> {
>> return reportRuntimeError(getMessage3(messageId, arg1, arg2,
>> arg3));
>> }
>>
>> This allows to write, for example, instead of
>>
>> Object[] args = { Integer.toString(base) };
>> throw Context.reportRuntimeError(getMessage
>> ("msg.bad.radix", args));
>> simply
>> throw Context.reportRuntimeError1(
>> "msg.bad.radix", Integer.toString(base));
>>
>> which is not only easy to read but also generates less code.
>>
>> I attach my patch to Context.java to implement this plus a patch to
>> ScriptRuntime.java that utilizes the additions. The patches are in
>> standard and context versions.
>>
>> If you think that this make sense to incorporate, I can send a patch
>> that utilizes this everywhere.
>>
>> ------------------------------------------------------------------------
>> Name: patch.context.Context.java
>> patch.context.Context.java Type: Plain Text (text/plain)
>> Encoding: base64
>>
>> Name: patch.std.Context.java
>> patch.std.Context.java Type: Plain Text (text/plain)
>> Encoding: base64
>>
>> Name: patch.context.ScriptRuntime.java
>> patch.context.ScriptRuntime.java Type: Plain Text (text/plain)
>> Encoding: base64
>>
>> Name: patch.std.ScriptRuntime.java
>> patch.std.ScriptRuntime.java Type: Plain Text (text/plain)
>> Encoding: base64
>>
>> Name: all.zip
>> all.zip Type: Zip Compressed Data (application/x-zip-compressed)
>> Encoding: base64
git-svn-id: svn://10.0.0.236/trunk@85289 18797224-902f-48f8-a5cc-f745e15eee43
Description
No description provided
Languages
C++
31%
C
21.9%
HTML
13.3%
JavaScript
12.9%
Java
5.1%
Other
15.5%