Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The kotlinx.io.core.String(ByteArray, Int, Int, Charset) function ignores the length and offset arguments on JS #11

Closed
mrapplexz opened this issue Oct 5, 2018 · 2 comments

Comments

@mrapplexz
Copy link

Description

Looks like the kotlinx.io.core.String(ByteArray, Int, Int, Charset) function just ignores the length and offset arguments on JS.
For example, the String(byteArrayOf(64, 64, 67, 67), length = 2, offset = 1) expression will return @@CC instead of @C.

Steps to Reproduce:

  1. Create a new Kotlin/JavaScript + Gradle project using IntelliJ IDEA.
  2. Make the build.gradle file look like that:
plugins {
    id 'java'
    id 'kotlin2js' version '1.3.20-dev-592'
}

group 'com.company.test'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    jcenter()
    maven { url 'http://dl.bintray.com/kotlin/kotlin-dev' }
    maven { url 'http://dl.bintray.com/kotlin/kotlinx' }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-js"
    compile "org.jetbrains.kotlin:kotlin-test-js"
    compile "org.jetbrains.kotlinx:kotlinx-io-js:0.1.0-alpha-17-rc13"
}

compileKotlin2Js {
    kotlinOptions.moduleKind = 'umd'
}
  1. Make the settings.gradle file look like that:
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "kotlin2js") {
                useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
            }
        }
    }

    repositories {
        jcenter()
        maven { url 'http://dl.bintray.com/kotlin/kotlin-dev' }
    }
}
rootProject.name = 'test'
  1. Create a new package named "com.company.test" and a "Test.kt" file inside it with the following contents:
package com.company.test

import kotlinx.io.core.String

fun main(args: Array<String>) {
    println(String(byteArrayOf(64, 64, 67, 67), length = 2, offset = 1))
}
  1. Build the project and run it using Node.JS (I've been using v10.11.0).
  2. The @@CC will be printed instead of @C 😞.
@mrapplexz
Copy link
Author

Looks like an array returned by the TypedArray#subarray(...) method uses the same buffer as the original array: The subarray() method returns a new TypedArray on the same ArrayBuffer store and with the same element types as for this TypedArray object. So, i8.subarray(offset, offset + length).buffer will return the original ArrayBuffer and will ignore the offset and length parameters :/.

@fzhinkin
Copy link
Collaborator

We're rebooting the kotlinx-io development (see #131), all issues related to the previous versions will be closed. Consider reopening it if the issue remains (or the feature is still missing) in a new version.

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

No branches or pull requests

2 participants