From fc960c62e3593aae71849d85c35a364ac19dfa57 Mon Sep 17 00:00:00 2001 From: David Richardson Date: Thu, 22 Oct 2026 14:10:19 -0600 Subject: [PATCH] Objective-J: Adopt general runtime fixes from the npm runtime Executable.setCode failed when the compiler produced no code after a compile error. This adopts that fix and the other general changes from the runtime published to npm as @objj/runtime, without its Node-specific changes. - CFDictionary.js: Add toJSObject, which returns the contents as a plain object - Executable.js: Return early from setCode when no code was produced - CPLog.js: Return early from CPLogPrint when CPLogDisable is set - Bootstrap.js: Accept SourceMapIncludeSource in OBJJ_COMPILER_FLAGS --- Objective-J/Bootstrap.js | 4 ++++ Objective-J/CFDictionary.js | 19 +++++++++++++++++++ Objective-J/CPLog.js | 1 + Objective-J/Executable.js | 2 ++ 4 files changed, 26 insertions(+) diff --git a/Objective-J/Bootstrap.js b/Objective-J/Bootstrap.js index 7f7be575f..a2477ceb8 100644 --- a/Objective-J/Bootstrap.js +++ b/Objective-J/Bootstrap.js @@ -70,6 +70,10 @@ if (typeof OBJJ_COMPILER_FLAGS !== 'undefined') case "SourceMap": flags.sourceMap = true; break; + + case "SourceMapIncludeSource": + flags.sourceMapIncludeSource = true; + break; } } FileExecutable.setCurrentCompilerFlags(flags); diff --git a/Objective-J/CFDictionary.js b/Objective-J/CFDictionary.js index f61412d37..3405f1382 100644 --- a/Objective-J/CFDictionary.js +++ b/Objective-J/CFDictionary.js @@ -171,6 +171,25 @@ CFDictionary.prototype.toString = function() DISPLAY_NAME(CFDictionary.prototype.toString); +CFDictionary.prototype.toJSObject = function() +{ + var jsObject = new Object(), + keys = this._keys, + index = 0, + count = this._count; + + for (; index < count; ++index) + { + var key = keys[index]; + + jsObject[key] = this.valueForKey(key); + } + + return jsObject; +}; + +DISPLAY_NAME(CFDictionary.prototype.toJSObject); + GLOBAL(CFMutableDictionary) = function(/*CFDictionary*/ aDictionary) { CFDictionary.apply(this, []); diff --git a/Objective-J/CPLog.js b/Objective-J/CPLog.js index 87e325cc7..c04bddcb0 100644 --- a/Objective-J/CPLog.js +++ b/Objective-J/CPLog.js @@ -192,6 +192,7 @@ GLOBAL(CPLogColorize) = function(aString, aLevel) GLOBAL(CPLogPrint) = function(aString, aLevel, aTitle, aFormatter) { + if (CPLogDisable) return; if (stream === undefined) { try { stream = require("narwhal/term").stream; diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 17dd66a02..1e6636541 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -219,6 +219,8 @@ Executable.prototype.setCode = function(code, sourceMap) { this._code = code; + if (code == null) return; + var parameters = this.functionParameters().join(","); var sourceMapBase64;