GithubHelp home page GithubHelp logo

Comments (4)

TooTallNate avatar TooTallNate commented on July 28, 2024

Do you have some code that I can reproduce the issue with?

from nodobjc.

bernhard-42 avatar bernhard-42 commented on July 28, 2024

See https://github.com/bernhard-42/node-cocoa-http

Without patch, calling via curl localhost:8080 -d '{"a":42}'

$ coffee app.coffee
[Class: PostConnection1]
server listening to port 8080
listening ...
expectsRequestBodyFromMethod
supportsMethod
processBodyData

/Users/bernhard/Development/node-cocoa-http/cocoa-http.coffee:124
        self.ivar("request")("appendData", postDataChunk);
                            ^
TypeError: object is not a function
  at /Users/bernhard/Development/node-cocoa-http/cocoa-http.coffee:91:7
  at /Users/bernhard/Development/node-cocoa-http/node_modules/NodObjC/lib/core.js:253:31
  at /Users/bernhard/Development/node-cocoa-http/node_modules/NodObjC/node_modules/ffi/lib/callback.js:52:23

With patch:

$ coffee app.coffee
[Class: PostConnection1]
server listening to port 8080
listening ...
expectsRequestBodyFromMethod
supportsMethod
processBodyData
httpResponseForMethod
{ method: POST,
  url: /,
  headers:
   { 'User-Agent': 'curl/7.37.1',
     Accept: '*/*',
     Host: 'localhost:8080',
     'Content-Length': '8',
     'Content-Type': 'application/x-www-form-urlencoded' },
  body: '{"a":42}',
  httpVersion: '1.1' }

from nodobjc.

bernhard-42 avatar bernhard-42 commented on July 28, 2024

Any idea whether this fix is correct or whether the issue sits deepr in import.js? - thanks

from nodobjc.

nw avatar nw commented on July 28, 2024

@bernhard-42 I think the issue is deeper.

@TooTallNate code that reproduces a similar issue, generating the wrapped value. In this case type is undefined completely.

var $ = require('nodobjc');
$.framework('Foundation');
$.framework('Cocoa');
var pool = $.NSAutoreleasePool('alloc')('init');

var result = $.CGWindowListCopyWindowInfo($.kCGWindowListOptionAll, $.kCGNullWindowID);
var windowList = $.CFBridgingRelease(result);

var aWindow = windowList('objectAtIndex', 0);

console.log(aWindow.ancestors()); 
// ['__NSCFDictionary','NSMutableDictionary','NSDictionary','NSObject' ]

console.log(aWindow.toString())
/* example:
{
    kCGWindowAlpha = 1;
    kCGWindowBounds =     {
        Height = 1440;
        Width = 2560;
        X = 1440;
        Y = "-540";
    };
    kCGWindowIsOnscreen = 1;
    kCGWindowLayer = 20;
    kCGWindowMemoryUsage = 1008;
    kCGWindowNumber = 14764;
    kCGWindowOwnerName = Dock;
    kCGWindowOwnerPID = 354;
    kCGWindowSharingState = 1;
    kCGWindowStoreType = 1;
}
*/

pool('drain');

Trying to access a property

aWindow('kCGWindowOwnerName');

produces the following error:

2015-08-13 17:59:23.262 node[85901:3004028] -[__NSCFDictionary kCGWindowOwnerName]: unrecognized selector sent to instance 0x101351770

/node_modules/nodobjc/lib/class.js:193
      else throw e;
                 ^
-[__NSCFDictionary kCGWindowOwnerName]: unrecognized selector sent to instance 0x101351770
    at ID.module.exports.Class.msgSend (/node_modules/nodobjc/lib/class.js:192:45)
    at rtn (/node_modules/nodobjc/lib/core.js:375:47)
    at app.js:27:15
    at /node_modules/nodobjc/lib/core.js:256:31
    at /node_modules/nodobjc/node_modules/ffi/lib/callback.js:66:25
    at ForeignFunction.proxy (/node_modules/nodobjc/node_modules/ffi/lib/_foreign_function.js:59:14)
    at unwrapper (/node_modules/nodobjc/lib/core.js:301:31)
    at ID.module.exports.Class.msgSend (/node_modules/nodobjc/lib/class.js:189:34)
    at rtn (/node_modules/nodobjc/lib/core.js:3

using ivar produces:

aWindow.ivar('kCGWindowOwnerName');
/node_modules/nodobjc/lib/class.js:193
      else throw e;
                 ^
TypeError: Cannot read property 'type' of null
    at Object.wrapValue (/node_modules/nodobjc/lib/core.js:181:24)
    at ID.module.exports.ID.ivar (/node_modules/nodobjc/lib/id.js:74:19)
    at app.js:27:19
    at /node_modules/nodobjc/lib/core.js:256:31
    at /node_modules/nodobjc/node_modules/ffi/lib/callback.js:66:25
    at ForeignFunction.proxy (/node_modules/nodobjc/node_modules/ffi/lib/_foreign_function.js:59:14)
    at unwrapper (/node_modules/nodobjc/lib/core.js:301:31)
    at ID.module.exports.Class.msgSend (/node_modules/nodobjc/lib/class.js:189:34)
    at rtn (/node_modules/nodobjc/lib/core.js:375:47)
    at tock [as _onTimeout] (app.js:60:14)

For sanity I enumerated over the NSObject to verify the keys, and everything looked good.

var keys = aWindow('keyEnumerator');
var key;

while(key = keys('nextObject')){
  console.log(key);
}
/*
kCGWindowLayer
kCGWindowName
kCGWindowMemoryUsage
kCGWindowIsOnscreen
kCGWindowSharingState
kCGWindowOwnerPID
kCGWindowNumber
kCGWindowOwnerName
kCGWindowStoreType
kCGWindowBounds
kCGWindowAlpha
*/

Worth noting: numIvars does not exist in this code

from nodobjc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.