Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

import {$,on} from "Sciter" fails. #12

Closed
4silvertooth opened this issue Nov 11, 2020 · 11 comments
Closed

import {$,on} from "Sciter" fails. #12

4silvertooth opened this issue Nov 11, 2020 · 11 comments

Comments

@4silvertooth
Copy link
Contributor

Check the sqlite db sample, it fails to load with this error.

warning:DOM: failed to load "/sciter-js-sdk/samples/sqlite/Sciter" file, error=2

@jsprog
Copy link

jsprog commented Nov 11, 2020

Note: I'm sharing this as I it may help fixing internal implementation.

I can confirm about receiving this error followed by:

Segmentation fault (core dumped)

Not sure what's causing this, but I discovered that the current implementation reports some errors when using Object.freeze({__proto__: null, ...}). Bundlers may use this during transformations.

// main.js
import mod from './mod.js' // OK
import { a } from './mod.js' // OK
import * as all from './mod.js' // OK but fails if the bundler converted it and used Object.freeze(__proto__:null...

// mod.js
export default 'module_default'
export const a = 'a-value'
export const b = 'b-value'
// After transformation by the bundler
var mod = 'module_default';
const a = 'a-value';
const b = 'b-value';
var mod_all = /*#__PURE__*/Object.freeze({
    __proto__: null,
    'default': mod,
    a: a,
    b: b
});

Reported error after running the code generated by the bundler:

terminate called after throwing an instance of 'qjs::exception'
Aborted (core dumped)

using @rollup/plugin-replace could fix this
// rollup.config.js
    ....
    ....
    replace({
        delimiters: ['', ''],
	    "__proto__: null,": ""
	})

@c-smile
Copy link
Owner

c-smile commented Nov 11, 2020

Check the sqlite db sample, it fails to load with this error.

warning:DOM: failed to load "/sciter-js-sdk/samples/sqlite/Sciter" file, error=2

Thanks, fixed by 294b71d

I've changed names of internal modules:

"Sciter" -> "@sciter"
"System" -> "@sys"
Added "@env"

So names of all internal modules start from @ sign.

@c-smile
Copy link
Owner

c-smile commented Nov 11, 2020

// After transformation by the bundler

Not sure why such transformation is required.

Also this works just fine:

const a = 'a-value';
const b = 'b-value';
var mod_all = /*#__PURE__*/Object.freeze({
    __proto__: null,
    a: a,
    b: b
});

console.log(mod_all.a,mod_all.b);

@jsprog
Copy link

jsprog commented Nov 11, 2020

svelte use a bundler like rollup to build the project and some transformations are applied:

  • compiling .svelte files.
  • many files -> less files (e.g: 1 javascript file and 1 css file).
  • using modern syntax not supported by current and older browsers, and the bundler should take care of the transformation (e.g: private class properties).
  • Sciter.js could benefit from the bundler to fix some npm packages to run with it.

I can confirm that the code above runs without issues, but the __proto__:null, generated by building the default svelte project (npx degit sveltejs/template my-svelte-project) is crashing the process (Windows and Linux). You also need to import * as all from './mod' in your code for this to lands into bundle.js. and I could run the app the moment I removed __proto__:null,

Likely, something else is getting affected by __proto__:null,, and I'll try to share the details the moment I discover something.

@c-smile
Copy link
Owner

c-smile commented Nov 11, 2020

but the __proto__:null, generated by building the default svelte project

proto is deprecated and please check: rollup/rollup#3140

@c-smile c-smile reopened this Nov 11, 2020
@jsprog
Copy link

jsprog commented Nov 11, 2020

Please see #13 (console.log fails with const object = { proto: null })

@jsprog
Copy link

jsprog commented Nov 13, 2020

@4silvertooth
How did you manage to run the sqlite sample?

@c-smile
Copy link
Owner

c-smile commented Nov 13, 2020

In usciter application that links SQLite statically and sets SQLite as a global namespace object: https://github.com/c-smile/sciter-js-sdk/blob/main/demos/usciter/usciter.cpp#L57

Sciter will have function importLibrary(dllname) to load native assets but it is not there yet.

@c-smile c-smile reopened this Nov 13, 2020
@jsprog
Copy link

jsprog commented Nov 13, 2020

I can see the reason now.

@intrnl
Copy link

intrnl commented Nov 16, 2020

Somewhat late now, but set freeze to false in Rollup's output options to remove object freezing for namespaces

@jsprog
Copy link

jsprog commented Nov 16, 2020

Thanks for the share. Actually, We didn't had problems with freeze but with console.log when used with objects with a null prototype #13. It's already solved.
Sometimes it's more safe to keep some sensitive objects frozen, and I'm doing this when writing some library modules.

Anyway, thanks for https://github.com/intrnl/vite-plugin-svelte

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants