File size: 972 Bytes
8f3f8db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function CroquetPlugin() {
  "use strict";

  return {
    getModuleName: function() { return "CroquetPlugin"; },
    interpreterProxy: null,

    setInterpreter: function(anInterpreter) {
      this.interpreterProxy = anInterpreter;
      return true;
    },

    primitiveGatherEntropy: function(argCount) {
      var rcvr = this.interpreterProxy.stackObjectValue(0);
      if (this.interpreterProxy.failed()) {
        return null;
      }
      if (!rcvr.isBytes()) {
        return this.interpreterProxy.primitiveFail();
      }
      window.crypto.getRandomValues(rcvr.bytes);
      this.interpreterProxy.popthenPush(argCount + 1, this.interpreterProxy.trueObject());
      return true;
    },
  };
}

function registerCroquetPlugin() {
    if (typeof Squeak === "object" && Squeak.registerExternalModule) {
        Squeak.registerExternalModule("CroquetPlugin", CroquetPlugin());
    } else self.setTimeout(registerCroquetPlugin, 100);
};

registerCroquetPlugin();